The touch-move rule in chess specifies that, if a player intentionally touches a piece on the board when it is his or her turn to move, then the player must move or capture that piece if it is legal to do so.
In older problems (often with an illegal position) the solver is asked to retract an illegal move to return to a legal position. Typical illegal moves are: putting self in check, moving out of turn, illegal e.p. or castling. Since the determination of the illegal move is not a logical exercise, these are usually classified as jokes. Then the touch-move laws constrain the next move of the player.
Note that the precise penalties varied over history, and were not universally agreed at the time. More scholarship is required to determine the precise version assumed by each older problem.
In more modern Touch Move problems, it is permissible to try out moves that possibly contradict the basic legal assumptions (e.g. unjustified castling and en passant). The opponent decides what the history of the game is, and if as a result the move becomes illegal, it is reversed. Another move must be made in accordance with all chess rules including the current FIDE touch-move rule (2018). However the touch-move rule is a misleadingly minor aspect of this whole concept.
4.3 Except as provided in Article 4.2 [J'adoube], if the player having the move touches on the chessboard,with the intention of moving or capturing:
4.3.1 one or more of his own pieces, he must move the first piece touched that can be moved
4.3.2 one or more of his opponent’s pieces, he must capture the first piece touched that can be captured
4.3.3 one or more pieces of each colour, he must capture the first touched opponent’s piece with his first touched piece or, if this is illegal, move or capture the first piece touched that can be moved or captured. If it is unclear whether the player’s own piece or his opponent’s was touched first, the player’s own piece shall be considered to have been touched before his opponent’s.