Where does the expression “to walk the plank” come from and What does it mean?

The expression “to walk the plank” means: to force out of office or position.

This refers to a method used in a literal sense for getting rid of undesired persons on shipboard, a method used primarily by pirates or corsairs, especially in the seventeenth century on the Spanish Main, for disposing of unwanted captives in the cheapest, most effective, and least messy way.

That is, a plank was laid over the side of the vessel, the captive, hands tied behind, was blindfolded and, by pricks of a dirk or cutlass, compelled to walk along that plank until he fell into the sea.