One can make an argument that, no, melody & harmony need not be in agreement, but that all depends on the kind of sound you're aiming for. It took 500 years of Western Art Music history for Charles Ives to pull that off with any great success.
Ultimately the real test of what "sounds good" is a matter of taste (on the part of the listener) & the composer's ability to argue their case through their music. While in the general case of Western Music one would write a melody that worked with the exisiting harmonies & countermelodies, that may not meet your specific need, nor be what you hear as you write. Either way: you will need to practice arts of melody writing to compose a good tune.
& one can never go wrong studying counterpoint. After all: everything is counterpoint.