Not P07, but my friend's TS had the same issue with the left side safety coming off. I had to file the notch for the sear spring in the safety a little deeper. It took very little time and effort. Once the notch was deep enough, the sear spring leg on the safety held the safety firmly in place, and didnt face any issue for hundreds of rounds.
In fact, I could pull the safety out of the slide with just a little bit of force, even with the detent installed. You should probably check if you can also pull out the decocker once its fully inserted.
I checked the p07 parts diagram, as I have not worked on the internals of this pistol, and there seems to be a notch in both the decocker and the safety for P07, in identical spots, which could be for the sear spring to hold it in place. Could be the reason for the problem, specially if the safety does not walk out while shooting, or cannot be pulled out with hand as easy as the decocker.
EDIThttps://m.youtube.com/watch?v=hwdA6QXJK9UAt 5:30 in the video, it mentions the decocking spring, not sear spring, in the P07 that hold the decocker in its place by having one of its legs in the notch on the left side decocking lever. Seems like the decocking lever might need replacement.
It could also be more complicated if the ejector that also holds the decocker in its place has an issue, specially if the safety lever also behaves similarly.
I am sorry, but this is the best I could figure out and share.