Disclaimer: This is all just my observations/theory. I have no other evidence to back it up.
It seems there is some form of throttling/cut off point when recursion would occur in the "OnSizeChanged" script e.g. calling SetHeight() from within it. This prevents the bar height from being updated until a later point (in this particular case it seems your next "OnShow"). By placing a GetHeight() call in the script handler you seem to be able to force the update to occur immediately. This will of course allow the recursion to occur, but you have a statement in there to break it.
Code:
local Castbar_OnSizeChanged = function(castbar, width, height)
if floor(height + 0.1) ~= castBarHeight then
local healthbar = castbar.hp
castbar:ClearAllPoints()
castbar:SetPoint("TOPLEFT", healthbar, "BOTTOMLEFT", 0, -4)
castbar:SetPoint("TOPRIGHT", healthbar, "BOTTOMRIGHT", 0, -4)
castbar:SetHeight(castBarHeight)
castbar:GetHeight()
end
end