The Spanish-American War brung a need for a shorter route between the Pacific and Atlantic oceans.
To make this a bit simpler, to get to like california in America, or parts of Africa back then, you had to sail ALL THE WAY AROUND South America which by boat takes around 9 months.
Imagine your aunt Beckie sending you a birthday present from Africa in 1905
and it not getting there till 9 MONTHS LATER
A canal build across Central America would make global shipping much faster and cheaper. It also allowed to move from ocean to ocean during war.
Basically they didn’t want to, or have time, to sail 9 months around South America every time they needed to get to the other ocean during the war, so they dug a big canal for boats to sail through as a shortcut.
I hope this helps!
and it not