The Wikipedia article on Post hoc analysis says "Bonferroni correction (This is properly used with planned, not post hoc, contrasts.)" but does not explain why the Bonferroni correction is properly used with planned contrasts and not post hoc ones. The Wikipedia article on the Bonferroni correction does not seem to explain or even mention this.
The Bonferroni correction can theoretically be used with post hoc contrasts, but you need to think carefully about whether it is the best option and how to use it correctly. It's usually not the best option for post hoc comparisons. One trap you can fall into is to look at the data (or the output), notice some things that look like they are or might be "significant", and only test those formally, with the Bonferroni correction computed just counting the tests you have formally done. But in looking at other comparisons, you have informally done other tests, and these need to be counted, too. One reference I have at hand: Dean and Voss, Design and Analysis of Experiments, Springer (1999), pp. 78 -92