Groups with the same cohomology as their pro-$p$ completions