You said entities so I thought you are talking about the common situation that you set up something that consists of multiple entities. In that case hammer sometimes draws a slightly larger “box” around the selected entities. Now when moving it does not use the origin point of eg your prop_door_rotating but that bounding box that is slightly off grid. The result is misaligned entities. The solution is skip brushes.
Valves models have properly set up origin points so with a grid of 16 or at lowest 8 you will always get good alignment. Of course sometimes you have to tie that in with your surrounding brushes. This is something I recommend anyways as textures are set up for certain sizes aswell.
If you are dealing with non-stock models and you encountered those issues the models just have “badly” set up origin points. In that case you have to just deal with it or do what sreap mentioned and change the origin point in a modeling software. Blender is my recommendation