We can't go back in time but, as a musician I think I can answer.
It doesn't have to be invented because it occurs naturally.
When people chant together in a large group, they have different pitched voices. It's natural for women and children to sing at least an octave above the men.
However there are intermediate voices. They may not sing an octave but a fifth (which is also a fourth seen from the other direction).
Because of the construction of our ears, certain notes go well together. Firstly unison, then octaves, then fifths and so on.
As well as the sound-detecting hairs in our ears, there is a theory that pleasant sounds have a neurological basis. I remain to be convinced but time will tell.
The key to pleasant music may be that it pleases our neurons. A new model suggests that harmonious musical intervals trigger a rhythmically consistent firing pattern in certain auditory neurons, and that sweet sounds carry more information than harsh ones. https://www.newscientist.com/article/dn20930-why-harmony-pleases-the-brain/
Therefore anyone who is not tone deaf (another subject that can be discussed) will naturally tend to slide their own pitch towards one of these 'pleasant' intervals. You can clearly hear that adjustment in progress here https://youtu.be/V37k31746IM?t=102 The woman in question clearly has no idea of harmony or fine control of the pitch of her voice. She simply slides her voice around until it sounds good. She is 'inventing' harmony in that sense but has only a limited choice of what is pleasant.
Polyphony is an offshoot of call and response singing - specifically work-songs. If the call and the response overlap then you have elementary polyphony.
Another effect is to put a melody over the top of a drone. https://youtu.be/lN1NbYUE8Ck
Polyphony can develop from this by a lead singer singing over the top of a simple melody. https://youtu.be/veiJLhXdwn8?t=136
In traditional African singing it is common for someone to sing or shout a phrase when inspired to do so.
Once the classical era came along then the story gets more complicated. I could expand on this.
Finally, when you talk about pipes. There was no widespread standardising of pitch between musical instruments until the classical period. Original pipes were simple whistles with one or two holes added. They were mainly solo instruments often played by solitary shepherds. Singers would fit in with the pipe. In fact that still happens in modern-day orchestras where everyone tunes to an A provided by the oboe (a wind instrument that is difficult to adjust the tuning of).
EDIT with regard to the very useful answer by flox.
I agree with flox's exposition. However it doesn't say why naturally produced sounds are pleasant. I'll argue that it is the receiver that is important. For example two sufficiently out-of-tune instruments sound horrible because of the beat frequency. But beat frequency is a natural phenomenon as well. So the answer by flox doesn't explain why listening to a beat frequency is generally considered unpleasant. (Note: I'm aware of lots of acoustic theory about organ pipes using beats to produce notes that sound lower than what is being played). However none of that deals with the human aesthetic. I think I need to address in my answer the human anatomy that might explain that (I've already talked about the neurological factor).
As a start I'll talk about information processing. Humans are bombarded constantly with a barrage of sounds that they have to unravel in order to make sense of. This is equivalent to doing a Fourier analysis on the fly. We can distinguish individual pitches and even the direction they are coming from. If notes are in harmony (exactly as flox indicates) then they stimulate the sensitive ear transducers with a similar resonance. Thus to a human a note and an octave above it sound almost the same. This is because the tiny hair cells in the cochlea vibrate with the same laws that flox mentions. The result of this is less information processing. White noise is a mix of all frequencies and at that point our nervous systems give up trying to separate sounds and simply lump the frequencies together. In a crowded room the information processing is at its worst because of all the cross-talk and mixtures of timbre and pitch. Harmony takes most of the strain out of this situation and gives our nervous system a rest.
So, I argue, perceived harmony is a product of the receiving apparatus. If evolution had come up with a different mechanism we might never be able to hear harmony at all even if the mathematics 'out there' was as flox correctly asserts.