The rule stats that if the same position has occured 3 times (according to your notation sheet, in the whole game.), a draw can be claimed, remember that you cannot make a claim on your opponent's move, so if you need to do the move for the claim, you must seal the move in annotation and call the TD, If your opponent made the move and it's your turn, then you can make the claim, without moving. If the same position has occured 3 times another move was made, then the position present cannot be claimed, unless it has can be proved (Usually with your notation sheet) that is has occured 3 times. Pawn moves and captures will break the rule ofc, cause the position cannot reoccure.
3 Move Repetition Rule

https://en.wikipedia.org/wiki/Threefold_repetition
@ Chess.com : Just watch out the "White Flag of Claim Draw".
(Both your examples presented above do keep the Claim Draw-flag inactive.)
Can someone who actually knows what they're talking about give me clarification on what the rule is? Let's say a position occurs 3 times but it is white to move in the first 2 but black to move the last time. Does that count? What if one side could castle the first time but couldn't castle the next 2. Does that count?