One element is when the pet has a very characteristic behavior right before death. For example, if a dog always steals socks and is found with a sock in its mouth when it passes away. It makes you remember the fun side of their antics. Another is when the death seems very peaceful and natural, like a pet just falling asleep and not waking up. It gives a sense of it being a gentle end.
Well, if the pet's death is related to something that was a big part of their funny personality. Let's say a cat that was always clumsy and one day it accidentally knocks over a small object and then passes away right there. It's sad but you can't help but chuckle at how typical it was of the cat. Also, if the owner can focus on the good memories rather than just the loss. If they remember all the funny things the pet did, it lessens the sadness.
The unexpectedness of some situations can make it less sad. For instance, a guinea pig that was always very proper and calm. One day, it got excited over a new piece of hay and started jumping around like crazy. Then it suddenly died. It's tragic but also makes you think about how that one moment of wild excitement was so out of character and kind of funny. And when the pet has lived a long and fulfilling life, it's easier to accept their death with a bit of humor.