I really curious about collision detection and raycast of unity. Is unity have a spatial hash grid which is working on background
Most if not all physics engines use a Broadphase which is a spatial acceleration structure to speed-up the detection of potentially colliding things; before the Narrowphase performs the more costly exercise of determining if they are actually colliding. There’s plenty of material online about this technique, nothing Unity specific is required.
Also, there are multiple physics engines used by Unity though.
Bounding volume hierarchies (BVH), sweep and prune (SAP) and regular grids are popular broad phase structures. Each one has strengths and weaknesses. Unity’s built-in, default 3D physics engine is PhysX -widely used by other game engines- which I believe uses an algorithm called “automatic box pruning” by default but can also use SAP. Docs may help: Rigid Body Collision — NVIDIA PhysX SDK 4.1 Documentation
Note that in recent Unity versions, you can choose which broad phase algorithm to use in the Physics settings: Unity - Manual: Physics