There are a couple of different out-of-universe reasons. One reason for the gray hue of many ships, as well as the death star, was that the early special effects crew built many models by "kit-bashing." To get the look they wanted, they glued together pieces from model battleship kits. So a lot of things ended up looking battleship gray by default.
The other out-of-universe reason was that it contributed to the "used future" aesthetic of the original Star Wars films. The full-sized X-wings used in some shots were, after they were originally built, found to be too bright and shiny looking, so the crew rubbed them down with dirt, to make them look used old and heavily used.
In universe, the color of ships is just pretty much irrelevant. It you want to spot something in outer space, the color doesn't really matter, only the size, how far away it is, and the total surface brightness. And for really small objects, even the surface brightness doesn't matter that much; small things are just going to be really hard to spot unless they are really close.