John Mueller of Google said again, .gov TLDs, top level domain names, do not get a ranking boost or preference in Google search. Having a .gov, just because it is a .gov, does not directly help you rank better.
However, a lot of .gov domain names have a lot of good quality links. That is probably why you would think .gov TLDs rank well.
But Google doesn't have a ranking signal that says, if .gov then increase the ranking of this page by X.
Here is John Mueller of Google on Twitter saying no to the .gov ranking benefit question:
No.
— 🍌 John 🍌 (@JohnMu) January 21, 2020
Forum discussion at Twitter.