This is a good question which is really asking as to how you can move a mass $m$ from position $A$ to another position $B$, a distance $h$ above position $A$, whilst at the same time doing no net work on the mass which has a downward force acting on it due to the gravitational attraction of the Earth - the weight of the mass $mg$.
Apply an upward force magnitude $F_{\rm external}$ on the mass equal in magnitude to the weight of the mass and start the mass off with an upward velocity $v$ at position $A$.
The mass will move up with a constant velocity when moving from position $A$ to position $B$ because no net work is being done on it (net force = $F_{\rm external}$ - mg =0) and the kinetic energy of the mass does not change.
You can of course have any value you like for the magnitude of the velocity.
With the mass starting from rest, apply a force $F_{\rm external}$ on the mass which is greater than the weight of the mass $f = F_{\rm external} -mg$ and after the mass has moved a distance $z$ reduce $F_{\rm external}$ so that it is equal in magnitude to the weight of the mass.
The work done on the mass $fz$ will equal the gain in kinetic energy of the mass.
This will give the mass an upward velocity and kinetic energy which will stay constant as long as $F_{\rm external} =mg$.
When the mass is a distance $z$ from position $B$ reduce $F_{\rm external}$ so that the net force on the mass is $f$ downwards.
The work done on the mass will now be $-fz$ and will equal the loss in kinetic energy of the mass.
The mass will stop at position $B$ because the net work done on the mass is zero $(fx-fx=0)$.
From this you can generalise and say that all you need to do is do an (infinitesimal) amount of work on the mass to get it moving when it starts off from position $A$ and then get that work "back" whilst the mass slows down and stops at position $B$.
When your teacher demonstrates the increase in potential energy by lifting a stationary mass on the floor and then placing it on a bench top this is what your teacher does.
Once you have convinced yourself that you can move the mass from position $A$ to position $B$ by doing no net work on the mass alone you can then apply the same ideas when you look at the mass-Earth system as the mass alone does not have gravitational potential energy, it is the mass and the Earth which has the gravitational potential energy.
So you either use the definition that the change in potential energy is equal to the work done by external forces in increasing the mass to Earth distance $=F_{\rm external} \times h = mgh$
or the change in gravitational potential energy is equal to minus the work done by the gravitational field in increasing the mass to Earth distance $= -(-mg \times h) = mgh$.
It is assumed that because the Earth is so massive compared with mass $m$ the movement of the Earth relative to the centre of mass of the mass-Earth system is very small compared to the movement of the mass and hence the work done by the force acting on the Earth can be neglected.