Suppose a player loses his footwear accidentally while playing and then scores a goal without wearing his footwear. Will it be considered a legal goal?
There is a law regarding such situation:
A player whose footwear or shinguard is lost accidentally must replace it as soon as possible and no later than when the ball next goes out of play; if before doing so the player plays the ball and/or scores a goal, the goal is awarded.
NB: hims056's answer is correct according to the law but I will add the following supporting information.
A lot is said in football about the referee's "interpretation" of the rules in a match. In the interpretation of this law, we should look closely at the term "immediately".
You will very rarely see a referee award a free kick against a player who passes or shoots with an un-booted foot. The player is at a disadvantage by being missing a boot so the generally-seen interpretation is that the player has had his shoe removed by accident.
With regards to the immediacy of the event, you're not likely to see a player running around for 15 minutes without a boot so pretty much any time from the loss of the boot up to the next time there is a break in the play could be deemed (interpreted) as immediate.
To sum up the interpretation as simply as possible; if the player has lost a boot and he hasn't had chance to replace it, then he will not have a foul awarded against him.
Earlier this year, Alessandro Matri scored for Juventus wearing no boot on his right foot.
Because it was an accidental, the goal would still be considered legal as there will be no violation.
"If a player loses his footwear accidentally and immediately plays the ball and/or scores a goal, there is no infringement and the goal is awarded because he lost his footwear by accident."