Quantum Berezinskii-Kosterlitz-Thouless transition in square-lattice magnets with easy-plane anisotropy