An alternate explicit construction:
First, you can continuously extend to the closure $\bar{Y}$ using the Lipschitz condition.
Then, since $\bar{Y}$ is closed, for every $x\in \mathbb{R}\setminus \bar{Y}$ one can find $x_- = \max \bar{Y}\cap \{ y < x\}$ and $x_+ = \min \bar{Y}\cap \{y > x\}$. Then just linearly interpolate: $ g(x) = f(x_-) + \frac{f(x_+) - f(x_-)}{x_+ - x_-} (x - x_-) $
But let me explain Leonid Kovalev's comment. Notice that fixing some arbitrary $x' \in Y$, we have that for any $x\in\mathbb{R}$ now chosen to be fixed
$ f(y) - f(x') + k|x-y| \geq f(y) - f(x') + k|x' - y| - k|x-x'| $
from triangle inequality. But using the $k$ lipschitz property you have that
$ f(y) - f(x') + k|x' - y| \geq 0 $
so the expression
$ f(y) - f(x') + k|x-y| \geq -k|x-x'| $
where the right hand side is independent of $y$. Or, in other words
$ f(y) + k|x-y| \geq f(x') - k|x-x'| $
so the expression you want to take the infimum of (in $y\in Y$) is bounded from below by some constant, and hence the infimum exists.