Quoting FIDE rulebook:
This capture is only legal on the move following this advance and is called an ‘en passant’ capture.
Quoting Wikipedia:
The en passant capture must be made at the very next turn or the right to do so is lost.
Why?
I know the basic story of en passant and I'll just paraphrase it here: A rule was added to let pawns move two squares forward on its first move. Someone said something like, what if a pawn uses this to escape from an enemy adjacent pawn? Then the basic pawn skeleton/framework would be changed! So we must have an en passant to preserve the same chess framework.
Okay that part makes sense, but why does it have to be on the very next move? Was that part of the rule only added later? Why was it added at all? When two pawns are diagonally adjacent confronting each other, they don't have to capture immediately or else forefeit the ability to capture. So the concept of the "ghost pawn", if you don't capture it immediately, and the other player doesn't move it, seems to me like it should still be there and available for capture as long as it's there.
Does anyone know why this part of en passant was created?
Optional Background: In case you're curious, I come from a programming background. Of all the special moves, en passant is (was, see below) the hardest to program. Not only is it the only move where the capturing piece moves to a blank square, but it's the only move that "disappears" if you don't take it. That means it's a move where the total board position is not enough information to generate all moves. (That's true for castling too, which already has its fair share of tricky rules.) Two enemy pawns could be adjacent on the 4th or 5th rank, surrounded by blank squares, but you still don't know if en passant is possible. You have to check the previous move.
Or so I thought. Now that I'm revisiting this, I figured out a clever way to implement en passant without checking the move log. Don't generate it at turn start. Generate it at move_take, specifically at the end of a 2-step pawn move. But store it in a special move array since the normal one gets cleared at every inc_turn. Then migrate and clear appropriately at gen_all_moves. That way, if ep is not taken, it doesn't generate itself on the next move because you didn't move that same pawn two steps on the next move. Just remember to check both sides of the pawn and create two ep moves if two enemy pawns are there.
Castling was implemented with the help of a "moved" boolean in every piece, which is also useful for a pawn's first move of course. Even if the King and Rook are in the right spot, you use that to see if the King/Rook has moved before. No need to check the move log. But I will say that Castling is now the hardest move to implement because you gotta check if the path is under attack. En passant is no longer the hardest now that I thought of the clever way.