Aside from being literally dangerous — what if something falls on your head? — walking under a ladder is considered bad luck for largely symbolic reasons. Early Christians believed that the number three was sacred for its connection to the Holy Trinity, and by extension, so was the triangle. When a ladder leans up against a wall, it forms that very shape, and walking underneath it “breaks” the Trinity. Not only was this blasphemous, but it might also attract the Devil himself.
Other historians have pointed out that a leaning ladder resembles the gallows, which use ladders so the person being hung can climb high enough to reach the noose. Either way, ladders have some not-so-great connotations.
Another origin of this superstition dates back to ancient Egypt. The Egyptians believed strongly in the power of the pyramids. Even a ladder leaning against a wall symbolized a pyramid because of its triangular shape. If someone walked under it, they believed that the power of the sacred pyramid was broken.
There are ways to undo the seemingly disastrous consequences. By walking back through the ladder, you can undo the harm and secure a second chance of better luck. Also, crossing your fingers until you see a dog can fix the situation.