Pure sine waves don't harmonize. If you play a sine wave at 400Hz, and continuously vary the frequency of another sine wave from say 700 to 900Hz, you won't hear any special consonance at 800. It will sound just as ugly as the neighbors.
What really harmonizes is the overtone series. The human voice, and instruments imitating it, have overtones at integer multiples of the main frequency. For example, if I sing a note at 400Hz, it will consist of a sum of sine waves at 400, 800, 1200 etc. When two such notes are sounding at the same time, and their overtone series partially match up - that's when you hear harmony. It's easy to see that it happens at small integer ratios.
The guy who came up with this idea (Sethares) also came up with an easy way to test it. He synthesized bell-like sounds whose overtone series aren't exactly integers. And sure enough, melodies with integer ratios of pitches sound horrible when played on that instrument, but melodies with tweaked ratios sound perfectly fine.
EDIT: Thank you HN! I believed this for years, but after writing this comment and getting some replies I went and checked, and it's not completely true. Matching overtones play a role, but simple frequency ratios sometimes work even without overtones, and there are proposed explanations for that. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2607353/#idm139...