At the checkpoint
TSA’s note on the entry: officers “may instruct travelers to separate items from carry-on bags such as foods, powders, and any materials that can clutter bags and obstruct clear images on the X-ray machine.” A pie in a box on top of your clothes is easy to lift out. A pie at the bottom of a packed bag is not.
What rides along with it
The pie is a solid. The things people pack beside it often aren’t. TSA’s Thanksgiving notice puts cranberry sauce, gravy and canned fruit in checked bags, and its travel tips give the test: “If you can spill it, spread it, spray it, pump it or pour it, and it’s larger than 3.4 ounces, it should go in a checked bag.” The 3.4-ounce rule applies to a tub of whipped topping the same way.
TSA’s pie entry doesn’t single out any filling, so a cream or custard pie gets the same yes. So do cookies and brownies.
In your checked bag
TSA’s entry sets no conditions for checked bags. Pies and cakes are a plain yes there.
Flying home from abroad
TSA’s answer covers screening at US airports. On the way home you go through the other airport’s screening first, and its rules are the ones that count there.
Coming home through US customs
CBP’s line is short: “You may bring bakery items and certain cheeses into the United States.”
That line is the whole of what CBP says. It doesn’t name pie or cake, and CBP’s agriculture page doesn’t mention bakery items at all.
Declare it either way. USDA says declared food brings no penalty, even when it’s refused. What happens if you don’t.

TSA puts this on every entry: “The final decision rests with the TSA officer on whether an item is allowed through the checkpoint.”