Most composers study music at a high level before attempting composition. It is not possible to compose for an instrument without knowing anything about it, but what most professional-level musicians know about instruments (even those that are not their own) is the range (how high or low it can play). From there, composers (or whoever is going to conduct the premiere of the piece) generally work with musicians at rehearsals to fix anything that is "unplayable". Although I wasn't there to see it happen, I have been part of this process with contemporary composers, and they generally just have a laugh about it and move on. Each instrument has quirks that really only masters of the instrument are aware of.
However, Mozart and Beethoven most certainly were geniuses, and had a certain level of intuition when it came to composing for different instruments.
Hope this helps!