Both the first and third terms are perfect squares.
$$ x^2 = \left( \color{blue}{ y } \right)^2 ~~ \text{and} ~~ 9 = \left( \color{red}{ 3 } \right)^2 $$The middle term ( $ -6x $ ) is two times the product of the terms that are squared.
$$ -6x = - 2 \cdot \color{blue}{y} \cdot \color{red}{3} $$We can conclude that the polynomial $ y^{2}-6y+9 $ is a perfect square trinomial, so we will use the formula below.
$$ A^2 - 2AB + B^2 = (A - B)^2 $$In this example we have $ \color{blue}{ A = y } $ and $ \color{red}{ B = 3 } $ so,
$$ y^{2}-6y+9 = ( \color{blue}{ y } - \color{red}{ 3 } )^2 $$