Sims will be removed from the counter as soon as they die. Ghost will only count towards limit when they are asked to move in.
So yes, sims who die will be moved to a hidden household that is hidden in Other Households section. This allows the game to delete the ghosts after about 90 days. Releasing the spirit means you delete them via gravestone. The ghost will never show up again but stays in the family tree (beware, after one update one of my sims' family tree got messed up. The sim released to netherworld is not found).