People who like and often hike a long distance will get the chance of the whole piece of toenail detaching. The mechanism is very simple: When going downwards along the mountain road, the toes stub the inside top of the shoe, the toenail tip will often be pushed backwards and cause the nail detaching.
When back home after a hard hiking, you may find one or several of your toenails are lifted up. Just trim the lifted part of the nail. Don’t need to dig out the root of the nail that’s still not detached. The new nail will grow underneath and push off the residue of the old nail. The toe area is the easiest infected part of a human body. So it’s very necessary to apply anti-bacteria oil/cream to the detached nail part in case of infection. Australian tea tree oil is a natural and very powerful anti-bacteria oil that’s used to prevent infection, I have been using it to handle wounds in fingers and toes, please see my the other article :Use tea tree oil to prevent and treat paronychia.
Finally, my suggestion is to always clip off the nail parts that are growing out of your toes. Not only to avoid the injury said above, but also the gap between nail and nail bed is the place that accommodate lots of dirts that are bad to your health.