Is there a way to hide the Share button from all the SharePoint online pages:-
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
For modern UI, anyway you can use a modern script editor to do the same thing. However once you switch to another page, the button still will returns. If you want to restrict users from sharing, it may be better to change the sharing settings to make only owners can share.
Then other members will not have this button on the right top.
You simply need to add a Script Editor or a Content Editor webpart and add the following script (QCB1_Button4 should be the id of the button, but this may change, check with F12 in browser):
Please mark the answer if it works for you!