When cops get to a scene where a mentally ill person did commit a crime, then they arrest them like any other person at first. If they still have a risk to hurt somebody else or themselves, or they already have hurt themselves, they should be brought to the hospital. If they are asked for it, a cop may ride in the ambulance too to keep everything safe.
When they get to the hospital, the cop should help the staff to restrain the person if they need to. After they get to the hospital and everything is under control, the cop should start to fill out all the paperwork they have to. They can leave the hospital once the person is cleared.
Once the person gets out of the hospital, they should get brought to the jail. The hospital employees should call the police station when the person is ready to leave the hospital.