What's wrong with the following sentence?

He was in trouble for acting like a tomfoolery.

It has to do with the part of speech of "tomfoolery." Here is a definition of that noun:

Main Entry: tomfoolery +t@m-!fU-lu-rE
Pronunciation: \ ˌtäm-ˈfül-rē, -ˈfü-lə- \
Function: noun
Date: 1812
Results
1812playful or foolish behavior
Merriam-Webster Online Dictionary copyright © 2009 by Merriam-Webster, incorporated

You could use "tomfool" in its place.

Sra

The following sentence has an error in the usage of the word "tomfoolery." While "tomfoolery" is a noun that means foolish behavior or mischievousness, it is not appropriate to use it as an adjective to describe how someone was acting.

To correct the sentence, you could rephrase it as: "He was in trouble for engaging in tomfoolery."