To get money.
IPO is a procedure in which a company sells its own shares to investors.
The money can then be used to expand the business operations, spend on R&D, pay back loans, etc.
Once the shares are sold to investors, the company itself does not get any money from the further buying and selling of the shares.
Example. XYZ Company sold 20,000 of its shares in an IPO.
Now, share market investors buy and sell these 20,000 shares among each other.