Move a use of `statestats` in `getpeerinfo` to within the section guarded by `if (fStateStats)`, e.g. `PeerManagerImpl::GetNodeStateStats` true, and pass an in-param by reference to const.
This is a backport of [[https://github.com/bitcoin/bitcoin/pull/22616 | core#22616]]