You have to use the Tilemap.PositionToTile event.
Here's an example for a 32x32 grid:
You just have to compare the tile the mouse was clicked at. If it's -1 it means there was no tile there. You could also compare it to an empty tile if you have one in your tilemap, you'd just change that number.
if it is empty, it re-positions the sprite to a 32x32 grid. If your grid is different you just have to change both numbers.