Its their way of communicating. Just like how dogs bark, its how they alert their owners to something,
When cats purr it is just a way for them to show how they feel. They do this when they are comfy so it's just them showing that they're comftorable and happy I guess? WHY do they? Because it's how they express themselves
Hope this helps!