I have always taken it for granted that they committed suicide since from our perspective they did a bad thing, and we also know that the ones who lived were hanged. But what reasons did they have from their own perspective? I know some of them were provided with cyanide pills in advance, which makes me wonder even more. Was it expected that they would be put on trial, and if so, why, given that leaders generally hadn't been tried before? Did any of them believe that they had done something wrong? Were they simply trying to protect secrets that they hoped would be useful to a future Reich?
The Moscow Declaration pretty explicitly said that Nazi political leaders and military officers would be treated as war criminals. Also, Christian Goeschel's Suicide in Nazi Germany cites both legitimate reports and propaganda of Soviet atrocities, solidarity with Hitler, and eschatological elements in Nazi ideology as contributing factors. Hitler in particular saw the spectacle of Mussolini's death and didn't want the same to happen to him.
I heard they all killed themselves cause they knew the end was near. They knew Germany had lost the war, they knew that if they weren't killed by Allied Forces they would be arrested and tried for war crimes. Some of them escaped Europe and started new lives but law enforcement continued to pursue and arrest Nazis for decades.
When they took their lives they were feeling failure, hopelessness, defeat, and the weight of the millions of Germans who died for a lost cause.