Hello and welcome. I'm sorry to hear your hammy is having some issues. Hamsters do actually scratch quite a lot as normal, as part of grooming, but if he has scratched himself sore then something might be going on. How old is he? And have you checked his nails? If his nails have got too long that could cause him to scratch himself sore. But another common cause could be mites. You can't actually see them with the naked eye. A vet would need to do a skin scraping and look under the microscope to diagnose if it was mites.
So I'd suggest checking his nails and if they're ok, then take him to the vet for an assessment and skin scraping. They will also be able to prescribe any medication needed. They might prescribe an antibiotic cream for the sores as well as do a skin scraping for mites.
If possible, it's better to see an exotics vet. The cost is no different usually, but they know a lot more about hamsters.
Which country are you in?