Where the ₹5 goes
Watch the price and your cash.
A company's shares trade at ₹335 . It announces it will pay ₹5 to its shareholders for every share they own.
The ₹5 leaves the company and comes to you, so the share is worth about ₹5 less. You haven't gained ₹5 out of thin air.