Deleting Photos: How do I delete across devices and cloud?
You didn't say what version of iOS or macOS you're using nor did you mention if you used iCloud or not.  This answer applies to the latest versions of all those.

If you are currently using iCloud to sync your photos across devices, once you delete a photo on any of those devices, it will also delete on iCloud.  Here is an Apple site about iCloud and how to use it.

iCloud is a syncing system designed to give you access to all your content regardless of what device you're using.

If you want to delete the photo from your device but keep it in a cloud solution, you need to use a 3rd-party cloud service.  Services such as Dropbox or Onebox can be used as a backup/storage solution.