Walls are perfect to exchange a huge amount of resources in favor for slowing down the enemy army significantly.
Walls have no restrictions in terms of maximum number and unlike most buildings consume no energy whatsoever. Combined with their cheap individual price, they are easily spammed at low HQ levels. This is especially the case as they only require a construction yard and nothing else to be built.
While all other buildings require a 1 tile gap in between their foundation, walls are the exception as they can be placed directly besides each other. They can not be placed besides other buildings without this gap though. This means they can fully block an entrance to a player's base as long as the construction range of the Construction Yard is big enough.
Furthermore they already block movement while they are constructed allowing for last second walling to lock out the enemy army. This can be especially valuable when using high range units like Torrent or when using units with a very long time between attacks like Thor.
It is also possible to just place a few walls at the entrance of the base as they are also very good at disrupting formations, lowering the strength of the attacking army noticeably if they don't take the time to destroy them first. This can make them very efficient at countering army compositions based around Chameleon.