The best way to clean a spice grinder depends on the instructions stated in the manual of your spice grinder.
The rule of thumb is that it's not dishwasher safe if it has electronics. If it has detachable bowls, then take them off and place them in the dishwasher.