How-to guide
As we discuss repeatedly, whether making a suppressor from an oil filter, a fuel filter, a flashlight, or anything else, what you really need are two things; 1) A can or tube-like expansion chamber – preferably with some media/baffles in there to absorb the expanding gasses, and 2) a threaded adapter to connect that can or tube-like expansion chamber to your barrel. The tricky part is always making certain you are matching the right threads for both your barrel and the can you have chosen.
These are the D-Cell adapter to screw it in, the steel-cap expansion cap, and the solvent trap, as seen on Amazon:
Long story short, there are adapters to catch harmful gun solvents that are the same thread-size as a Maglite flashlight. They're only built for that, and it's completely legal to install or sell them. Adding the baffles to suppress the gasses, sounds, and flash, well, they sell those too (the article has links), but they can't sell them to build a silencer, but for other purposes.
ivanivan also added that this does have additional legal hurdles in the real world in the United States, namely purchasing a silencer stamp as tax:
FWIW it is perfectly legal (US Federal law, the ~40 states where suppressor ownership is legal) to build your own suppressor. BUT you must apply for and receive back the NFA tax stamp before you begin. Even having the parts around can lead to a conviction for "constructive possession". Also, there are restrictions on what you can do - swapping out baffles or a baffle system may be considered making a new suppressor...
Since Amazon and online gun-stores aren't currently running in Rick's universe, he probably came upon the adapters in a gun shop and looted them.