When the world was younger, the principal defence against attackers was the castle, so effective before the age of gunnery that the only way to subdue it was to undermine its walls. To stop the enemy doing this, defenders evolved several techniques, one of which was to build out structures from the tops of the walls so that stones, boiling oil or other deterrents could be dropped on those below.
At first these structures were of wood (called hoardings) but they were later reconstructed in stone, most commonly over the particularly vulnerable gatehouses but in some cases all along the walls. These were the machicolations. A modern reference:
With its huge, menacing tower, watchbox, and multiple tiers of battlements (replete with arrow loops and machicolations concentrated over entrances), the building is fiercely defensive in look and capability, and it could as easily -- perhaps more easily -- be called a fortress.
The Renaissance Quarterly, Dec. 1999. The author is describing the Palazzo Vecchio in Florence.
The word came from the Old French machicolor, a compound of Provençal macar, “crush”, and col, “neck”, a graphic description of the result of being bombarded with stones from on high while you were trying to dig.