This really depends on the type of berries.
Hamsters can eat some types of berries in moderation as most of them do contain a lot of sugar. Eating too many berries will cause them to get sick.
They however cannot eat wild berries as they could be dangerous for their health with insects, parasites and possibly bacteria on them.
Also if you want to learn if hamsters can safely eat raspberries specially check out this article.