Aligning rotation to target along z axis
With this snapping options, and in particular with "align rotation to target" checked:



Moving an empty, you can notice that the Z axis is align to the target face normal and Y axis is up for the lateral faces:



But strangely this is not the case for a mesh:



Though, if you place a first mesh, then duplicate it, you can have the wanted result:



Duplication is not actually needed, you can place the object on a first face then move it again.

In my opinion (this is only an opinion), the code behind may do so that the rotation is minimal when snapping.

PS: locking rotation is not needed here.