504 error is likely a server related issue. Therefore, ask your host why the 504 is occurring.
Your error_log file may also explain it. So please check the error logs on your server. If you need help locating them, ask your hosting provider to help you with that.
Meanwhile, — to rule out any plugins and theme — please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.
If you can install plugins, install and activate “Health Check”: https://www.ads-software.com/plugins/health-check/
It will add some additional feature under create a new menu position Tools > Site Health.
On its troubleshooting tab, you can Enable Troubleshooting Mode. This will disable all plugins, switch to a standard WordPress theme (if available), allow you to turn your plugins on and off and switch between themes, without affecting normal visitors to your site. This allows you to test for various compatibility issues.
There’s a more detailed description about how to use the Health Check plugin and its Troubleshooting Mode at https://make.www.ads-software.com/support/handbook/appendix/troubleshooting-using-the-health-check/