first thing:
instead on key released, I would recommend using player is not moving, for when I moved by using the arrow keys the pinning didn't work..
second thing:
Maybe pinning the player isn't the best option here..
setting the player's position to the platform minus or plus the current location of the player compared to the platform could be a better option.
limiting the player's x and Y while overlapping the platform would be something like:
player is over lapping platform - player set x to clamp(player.x,platform.x-0.5*platform.width,platform.x-0.5*platform.width)
player set x to clamp(player.x,platform.x-0.5*platform.width,platform.x-0.5*platform.width)
If I'm correct.