If it wasn’t the case, people would just step off the pitch to make an (otherwise onside) attacker offside. Think about it
But when has that ever happened. Why should a defending team be punished for having a player off receiving treatment? If a player deliberately steps off the pitch that is a cautionable offence