That is a question of buoyancy when you add the sugar to the water and let it dissolve it increases the density of the water so that the egg floats in the center of the glass.
I think because it is not anough density I the water but salt has anough density.
An egg does not float in sugar water only in salt water because salt takes less at floating things