How to determine the required RPM for a 3.5-inch floppy disk as disks can apparently require different speeds?
Now, or back then?
In general, drive speeds are rather fixed with disk type and system.
Speed for most systems is 300 or 360 RPM, except a few outliers and variable speed drives.
How does a floppy drive know what RPM speed to use and if it is compatible with that disk?
Err ... because it is compatible? A non compatible disk will simply not read satisfactory. Compatibility is reached by building a system with the same parameters. All parameters of a floppy format, including the default RPM, are system specific. Thus no need to adjust outside of what it is made for.
Without any further ado IBM PC drives will only read IBM PC disks of the same type. Same for Apple drives doing Apple disks and so on.
For example the IBM 3.5 inch drives always rotate at 300 RPM. No matter if formatted for 320 KiB or 2880 KiB capacity. Selecting the right read/write parameters is a different story.
Similar a 5.25 inch HD drive will always rotate at 360 RPM. Compatibility with DD (as bad as it worked out) is done by modifying the read/write speed by 5/6th in the controller and double stepping.
[Addendum: The questions you're issuing in fast sequence sound a bit as if you're beating around the bush without much target to look for. It might be helpful to separate in drive detection vs. media/format detection, as well as maybe adding for what purpose the information is needed.]