This is situational.
I don't do two separate rolls, when it's a standard pickpocket or reverse pickpocket situation, IF the initial Sleight of hand is a success, but that's a DM call, as it is written.
So for instance, you want to reverse pickpocket a letter into someone's pocket. First, I have you roll to see if they notice--Dexterity (Sleight of Hand) check contested by the creature’s Wisdom (Perception) check.. If they don't notice and the sleight of hand is a success, I assume it's a success as far as it being carried out. (This makes sense to me because if it goes smoothly it won't be noticed.)
But if they DO notice, I THEN have the player roll to see if they got the job done anyway. So, you're picking their pocket, they notice, but you manage to get the wallet just as they notice. That would be Dexterity (Sleight of Hand) check, difficulty determined by DM, not contested by the victim. The victim might later be able to get it back or something but that's a whole different set of rolls.
If you're reverse pickpocketing, say, a damning letter onto their person, they can notice, but it might get in a pocket anyway. Of course, afterwards they'll take it out. But they might still have it in their hands at the right time. If it's some kind of magical incendiary they may have time to toss it away before it goes off. (They would roll for that themselves separately).
The exception to this rule, is if I am building suspense and it's particularly difficult--like line of sight is coming in and out because of a crowd of something. In those cases, the subject might not notice, but it's still possible to fail, and for the player to try again. In this case, I reverse the order of the rolls--first they roll for successfully pick pocketing, and then I have them roll the sleight of hand. It builds suspense, because the player can fail to pickpocket, but the subject still might be unaware, and the player can try multiple times.
With picking a lock at a distance, going unnoticed is totally separate from a success or not, depending on how close the noticer is to the lock.
The distance of the person noticing from the lock, determines whether them noticing would have any impact on success. So, if the person noticing the lockpicking is less than 5 feet away, I have them roll for the sleight of hand, and that might stop the attempt--basically, I handle it like pickpocketing.
But, if the guards are more than 5 feet away, I do both rolls at the same time, the sleight of hand, and the roll to pick the lock. Both are done at the same time, and while the person noticing might react, they are unlikely to prevent the success or failure of the person trying. Generally I give the player two dice, and assign different colors to the different things, and they roll them simultaneously. That's just DM flair.
Ultimately, it's up to the DM to decide what's fair, but this is how I handle these. Technically, and I do think you want to be technical here, there are supposed to be two rolls. One to see if you are noticed, and one to see if you are successful. I just handle it situationally, the better not to waste time on things, or the better to build suspense.