When the entity executing a command function is moved by a tp command within that function, subsequent commands within the same function will still be executed at the original position of the entity. For example, a function containing the following commands
tp @s ~ 250 ~
summon minecraft:armor_stand ~ ~ ~
when executed by the player will move the player to y=250 but will summon the armour stand at the player's original position.
I can work around this by prefixing the summon command with execute at @s run
but this would mean potentially making this change to every command that might possibly follow a tp of the executing entity.
The function is ran at the coordinates you specify, not at an entity, it is intentional that it doesn’t move when you move the executor; use execute to update the execution position.