Why was my penis so unpredictable before I hit 20?

You're a male teen. It was happening to all of your same-age male friends as well. We all learn to conceal unexpected / embarrassing erections. As things slow down over time, you'll remember and laugh. Love wisely and responsibly, and enjoy who you are.