That sucks hun, 2 years is pretty good for a hamster. Sounds like he may have had some sort of repiratory ailment from your description. Sorry for your loss.
Rodents in general are pretty succeptable to respiratory illnesses, more so when they are captive/ caged. From what you described, it sounds similar to a lot of animals I have seen and kept that died due to to what you could call kennel cough for rodents, or possibly pneumonia and pulmanary edema. It sucks, but it is unfortunately common