There is a checkable/uncheckable option called Block offensive words under Settings → Voice input & output → Voice recognizer settings.
In Android 8.1, that setting is in Settings → System → Languages & input → Virtual keyboard → Google voice typing → Block offensive words
For Samsung phones, the settings are named slightly differently: from the Settings app, try Language & input → Voice search settings → Block offensive words. This of course only works with the integrated Google voice recognition.
You also have to go to the gboard where the virtual keyboard is and also turn off that block for offensive words
For Android 4.3 (and possibly earlier versions):
Settings → Language & input → Google voice typing (settings) → Block offensive words
For Samsung S8+: Settings → General management → Language and input → On screen keyboard → Google voice typing → Block offensive words