There is an entire genre built for this, usually called serious games — titles designed with education as the goal rather than entertainment alone.
The mechanics are straightforward. A learning game pressures the player to pick up new knowledge in order to beat a timer, clear a level, or avoid losing a life and starting over. Because progress depends on understanding the material, the learning happens as a side effect of wanting to win.
Every level needs something to aim at. Without a clear objective at the end, players disengage and the teaching stops working. That is the design principle serious games are built around: wrap the lesson in a challenge worth completing.