Ah the offside rule! Traditionally explained using salt and pepper shakers on the kitchen table!
Essentially, when the ball is passed forward by the attacking team, the attackers (specifically those looking to run onto that pass) must have 2 of the opposition players between them and the goal they are attacking. In almost every scenario, 1 of those 2 players will be the goal keeper so essentially what the offside rule prevents is attacking players standing beyond the defenders at the time the ball is passed. As soon as the ball is passed they are free to make their run beyond the defenders so the skill element is timing the pass and the run to perfection so that by the time the ball arrives at the attackers feet they are beyond the last defender but ‘onside’.
I will screenshot the Spain goal when I get back home to put that into context but essentially Lamal moved fractionally too early and was beyond the last defender when the pass forward to him occurred making him ‘offside’ and resulting in a free kick rather than a goal



