A musical instrument is anything that can produce a sound that we find pleasant. From that point of view, it can be more or less anything. Hitting two rocks together would produce a sound. But the music comes from making intended patterns of sound. There is no difference between two rocks and a drum beaten by hand. Both make a sound when they are hit - they are percussion instruments.
To most people an instrument becomes a musical instrument when it can be tuned in some way so that it can make sounds - notes - on a musical scale.
Most of the very early musical instruments would have been made from animal skins, bone and wood. They may well have been produced a million or more years ago. But they have not survived. The first object made to produce a variety of sounds and of which traces survive was probably the flute - and that was produced nearly 70,000 years ago.
Of course, as people migrated, so they took their musical instruments with them. They also came into contact with other people who had their own musical instruments, and the knowledge was shared.
Instruments have developed most rapidly in the last few hundred years as music became organised and people began to draw audiences to listen. For hundreds of years the money came from the wealthy, such as kings and princes who wished to have music in the courts. This then provided the money needed to pay for composers, musicians and musical instrument makers to develop newer and better instruments. More recently, the money has come from the public, who are now welcomed into performances that would not have been open to them before the 19th century.