Sadly this is far more complex than one would assume. In Cloud no 'move' REST API exists, so this wont happen until JIRA adds such an API in Cloud.
In server this could fail very often due to different workflows, field configs, screen schemes etc. The manual move operation via the UI requires a several step wizard. Automating this isn't ideal since it will most likely fail more often than it will pass.
Warning: The workaround results in certain fields being lost i.e. history, comments, attachments, and linked issues
For a workaround, see https://docs.codebarrel.io/automation/kb/move-issue.html