The folded, ridged layers inside a cardboard box create narrow gaps that suit a cockroach's flat body perfectly. Once inside, a cockroach has a dark, enclosed space where nothing bothers it, a bit like moving into a block of tiny units that someone built just for them.
There's also a food angle most people overlook. Cockroaches can eat the glue and starch that hold cardboard together, so a damp or aging box can become both a home and a snack. Add the warmth that builds up in enclosed garages or cupboards, and you've got conditions that suit them beautifully.