Akinfenwa headed the Cobblers ahead from Joe Widdowson’s cross before George Miller curled Stanley level.
Rommy Boco lashed the hosts into the lead but substitute Jake Robinson levelled from close range.
Emyr Huws’ cross was headed home by Akinfenwa to put the Cobblers back in front before he completed his treble with a neat volley.
Northampton Town manager Aidy Boothroyd told BBC Radio Northampton:
“He (Akinfenwa) seems to be thriving at the minute. He was out of the team, he’s come back into the team and he’s proving his worth.
“I think Adebayo is a fantastic player; he’s better than League Two but I think that about a lot of our lads.
“I guess it’s like my kids; I don’t give them what they want, I always give them what they need. I always listen to them.”