I ran across this thread searching for a solution to this same problem, and ended up getting an idea from it that worked for me (on Blackberry KEYone running Android 7.1.1, FWIW):
Go into an app, bring up the voice dictation listening screen, then tap the gear icon there. In the settings screen that comes up, disable "Use offline speech recognition"
This works consistently for me - if I say "yeah comma that sucks exclamation point", the resulting message is "yeah that sucks" every time when I have Offline Speech Recognition enabled, and "yeah, that sucks!" every time I have it disabled.
I think this is the core of the issue, which explains why being on wifi or not and having background data restricted or not would effect it. If the recognition runs through Google's servers, you get punctuation; if it stays local inside the phone, you don't get it.
Hope this helps someone.