Instruments don't just produce one frequency at a time. When you play a single note on a melodic instruments (like piano, wind instruments, string instruments, etc.), you produce many different frequencies at a single time--a whole spectrum is produced. But this spectrum isn't random. It pretty closely follows the harmonic series, which can be thought of as the "ideal" values that the frequencies would have. The higher, often fainter frequencies that are produced are called overtones. (To read more on those, check out my answer here.) When the overtones match the harmonic series, it sounds harmonious and we get the sensation of hearing a single note/pitch. Here's an example of a waveform produced by a flute:
But when you strike a drum, the spectrum of frequencies deviates quite a bit from the harmonic series. Yes, there's often a single loudest frequency, but the overtones don't match what we expect to hear from a single-note/melodic instrument. As a result, our ears don't get the same sensation of hearing a single, defined pitch. It sounds more like a blunt collision than a defined note. For this reason, it would be much more difficult to recognize a melody on a drum than on a violin. This is called inharmonicity. A single strike of timpani produces a spectrograph like this:
According to hyperphysics, the overtones theoretically would be these multiples of the lowest/fundamental frequency: 1, 1.35, 1.67, 1.99, 2.30, 2.61. This deviates quite a bit from the harmonic series, where the overtones are integer multiples of the lowest/fundamental frequency.
This might raise the question: why aren't the overtones of a drum harmonic? (Harmonic = integer multiple of the lowest/fundamental frequency.) It comes down to this: a vibrating circular membrane has an extra dimension within which it can vibrate. This extra dimension gives rise to both symmetric and asymmetric vibrations. For timpani, the symmetric vibrations all produce inharmonic frequencies which aren't integer multiples of the fundamental frequency. And only 5-6 of the asymmetric vibrational modes are harmonic. Those are called the "preferred modes," and they're far and few between compared to the overtones of a melodic instrument.
But beyond this, there's another logistical reason why drums aren't as well-suited for a melody as melodic instruments. Drums are tuned in advance of a performance and many can't really be re-tuned on the spot. However, there are jazz drummers who use a technique called "melodic drumming." One of the most well-known is Ari Hoeing. Here's a video of him playing Billie's Bounce. In his intro, you'll see him pushing down on the drums to increase the tension and produce a higher pitch. At 1:53 when the main melody begins, you'll see him playing the actual melody of the song. It's recognizable, but compared to the saxophone, it's much harder to distinguish what notes the drums are playing.