What counts as stalemate
It must be your turn, your king must not be in check, and every move you might make must be illegal. That usually means a king with nowhere to go and no other pieces able to move.
Stalemate is a draw, not a win for either side. It is the defender's best friend in lost endgames and the most common way beginners throw away a won game.
How to avoid stalemating your opponent
Before every move in a winning endgame, count the enemy king's legal moves after your move. If the answer is zero and you are not giving check, find another move.
With king and queen against king, keep your queen a knight's move away from the enemy king as you shrink its box, then bring your own king up before delivering mate.