This procedure is called " completing the square ".
The starting expression is
y = x^2 - 6x
You want to extract the square. You write an equivalent / (an identical) expression
y = x^2 - 2*3x.
You transform it to this equivalent form
y = (x^2 -2*3x + 9) - 9
by adding and subtracting 9.
You extract the square
y = (x-3)^2 - 9.
It is just the form you want: h= 3; k= -9.