They blow up randomly as far as I know. If you try that potion again, it won't necessarily blow up, but it may blow up a number of times in a row, or it may work perfectly fine.
To eliminate the risk of potions blowing up, you will want your alchemy up to level 3
