We could leave it at that, but I am a fan of over-analysis. In what sense is it rational to limit your own decisions? How can it be beneficial to punish your future self? I will offer three levels of explanation.
One level deep
We behave irrationally. But that does not mean our behavior is unpredictable. My boyfriend can predict that if he makes the promise to me, he will go to the gym. If he does not make any promise, he will not go to the gym. Knowing this, it is rational to choose to make a promise to me. His overall pattern of behavior is irrational, but his response to his own pattern of behavior is rational.
Two levels deep
Our present selves and future selves have different preferences. Thus, we can imagine a two player game, roughly represented by this payoff grid.
In this grid, PBF represents the present boyfriend, and FBF represents the future boyfriend. First PBF makes a decision, then FBF makes a decision, and the payoffs are represented by the numbers in the corresponding box. Each player prefers a higher number of their own color, and doesn't particularly care about the other player's payoff.
I admit that I never bothered to take a class on game theory, but I think this is pretty easy to analyze. As I said in the previous level, it is rational for PBF to make a promise. But unlike the previous level, we can see that FBF's choices are also rational, it's just that they follow a different preference ordering.
Three levels deep
The previous level begs the question, why does a single person have different preferences at different times? I'm not sure I can show this to be rational, but I can put it in a larger framework. It's called discounting.
The choice of going to the gym basically has two consequences. The first consequence is that you have to work hard at the gym. The second consequence is that you become more fit. Each of these consequences is associated with a particular time. The hard work at the gym is associated with the near future, and the fitness is associated with the far future. Because the fitness is in the far future, its perceived value is diminished by the discounting factor. The discounting factor is a decreasing function of time, so that far future consequences are more diminished in value than near future consequences. This function is called the discounting function.
This is a diagram showing the discounting functions of the present boyfriend (PBF, green) and the future boyfriend (FBF, blue). As he gets closer to the time of going to the gym, its perceive value increases in magnitude, as does the perceived value of the fitness. However, working at the gym has a negative value (at least in his case), so its perceived value is actually becoming more negative.
Within this framework, it is possible that the rate at which the gym value grows more negative is greater than the rate at which the fitness value grows more positive. It's possible that my boyfriend's preferences could flip.
But note that this requires a certain shape of discount function. Economists usually talk about two particular discounting functions. The exponential discounting function just decreases exponentially. The hyperbolic discounting function decreases like 1/(t+C), where t is the time and C is a constant. With an exponential discounting function, preferences will never flip (except where some consequences occur in the past). With a hyperbolic discounting function, preferences may flip.
Basically, with hyperbolic discounting, we strongly value consequences near the present, but all the consequences in the distant future look about the same, even if those consequences are actually relatively far apart from each other. Thus, from PBF's point of view, the gym workout and resulting fitness are both discounted by about the same amount. But from FBF's point of view, the fitness is discounted much more than the gym workout.
From a certain point of view, discounting makes rational sense. Future consequences may simply not happen the way we predict. An intervening event could prevent their occurrence, or further information could put our predictions into question. If the intervening event mostly occurs when the future consequences are in the near future, then hyperbolic discounting makes more sense than exponential discounting.
On the other hand, I'm pretty sure this is not what is going through my boyfriend's mind when he flips preferences. Discounting is sort of an inherent component of our thinking. Maybe it's a heuristic rule we learned when we were young, or it was evolutionarily adaptive (or neither, or both). Whatever the reason, it appears to describe our preferences.