When were Muskets considered obsolete and phased out of European Armies?
There is an implication in this question that is not a hundred 100 % correct, which is that a gun is either a musket or a bolt action (or I assume any later form of mechanics of small firearms, like the different ones in semi-automatic firearms).
So, the classic musket is a smoothbore (i.e. lacking rifling to stabilize the bullet) and muzzleloaded gun (i.e. loaded in the front directly in the barrel, normally using a loose ball, powder and padding) and the bolt action is a rifled (using rifling) and breechloaded with an bolt-action mechanic (a fairly advanced mechanic built for cartridges that allows for repeated fire without reloading the gun) repeater rifle.
There are many other forms of firearms that are neither strictly traditional muskets or bolt actions, such as rifled muskets (often called simply rifles), lever action repeater rifles, pump action, revolvers etc.
So, I assume your question is when the bolt action replaced the musket as the primary gun for infantry in Western armies; The musket started to being phased out early-to-mid 19th century and the bolt action became dominant in the mid-to-late 19th century.
So how did the bolt-action rifle come to be developed?
Now, rifling (creating small groves on the inside of the barrel to make the ball or bullet spinning which creates a more predictable flight path) the was known practically for as long as there was muskets, but for an array of reasons (harder to maintain, more costly, more unreliable and not really that efficient in combination with the balls that where used for ammunition in the era) never caught on in a major way until late 18th century.
The cartridge (primer, propellant and bullet pre-packaged), another key component, was also an technology almost as old as the musket itself, with two major caveat, the primer was separate and it was made out of paper. The final step needed was the percussion cap, which was invented in early 19th century, which allowed for a fully integrated cartridge that would fire reliably.
The third part that is needed, an advanced breechloaded mechanic, is however a later invention, and was the final piece of the of the puzzle. I write an advanced breechloaded mechanic because there was many alternatives being tested and while the bolt action is arguably the most efficient, almost all of them was vastly superior to muskets. This is why you also see several different version of repeater rifles being tried in the period of ca 1840 - 1900 with lever-action (think cowboys) being the most successful alternative (besides bolt-action).
NB: The first bolt-action used in major conflicts where strictly not repeaters such as the Needle Gun used by the Prussians during the wars for German Unification, but would feed one paper cartridge a time in to the mechanic. However, this weapons proved to be so superior regardless, that they where quickly adopted almost universally once they saw combat (even though an old Swedish report I have of the Austrian-Prussian war really downplays the importance of the then modern Prussian Rifle) .
So what happened during the 19th century that allowed for a vastly superior rifle and mechanic to be developed? Industrialism and machine tools. Mechanics as bolt action need to be really tightly done for the weapon to function reliably, fire straight and to be safe, and before the industrialism and machine tools there was really no way to do this in the mass economic scale needed for military use.
More of course can be said, but this might be of interest for you.