Thanks for this report!
Although this isn't ideal, it is actually intended.
Gonna go into waaaay too much detail, but if you are curious read on!
The first reason it was implemented this way is to prevent players from buying/undoing item buys to heal faster. The way it works, is when you buy an item with health, the game will increase your max health, and then on the next tick heals you for an amount equal to the amount of health you gained. The obvious solution is then on item undo, also reduce your current health by the amount of health the item had. The problem with this solution is with the old item Spirit of the Ancient Golem (which gave you more health based on a % of your current max health). This made it so the amount of health an item gave wasn't always the same, and ultimately the current implementation is a result of that. We could probably address this (there are likely other abuse cases I am missing) but there is also a possibility we introduce another item with a similar effect, in which case this bug will return.
TL;DR the game will remember your health when you buy an item, and revert to that value after an undo.
Again, this isn't ideal, but I hope it at least gives some insight into why it is this way.
Hope this helps!
http://boards.na.leagueoflegends.com/en/c/bug-report/ErK5IxLG-shop-refund-resets-gealth-to-level-it-was-at-when-shop-page-was-opened?comment=0005