Suppose $K\subseteq \mathbb{R}^n$ is compact, $f: \mathbb{R}^n \rightarrow \mathbb{R}$ a function such that $f|_k$ is $L$-lipschitz and $f=0$ outside of $K$ and in $f|_{\partial K}$.
Is $f$ Lipschitz?
My try: if $x,y$ are in $K$ or outside $K$ then $|f(x)-f(y)|\leq L|x-y|$.
However is $x\in K$ and $y \notin K$? Taking $x^*$ a point on the segment from $x$ to $y$ that is also in $\partial K$ we have $|f(x)-f(y)|=|f(x)-f(x^*)|\leq L|x-x^*|\leq L|x-y|$.
Is this correct?
Your argument it fine. You don't need that $K$ is compact, only that is is closed (so that $\partial K \subset K$).
In the case $x \in K$, $y \notin K$ I would elaborate on why the segment from $x$ to $y$ contains a point $x^* \in \partial K$, and that is a connectedness argument:
Let $S$ denote that segment from $x$ to $y$. If $S \cap \partial K$ is empty then $x \in K^0$, $y \in K^C$, and $$ S = (S \cap K^0) \cup (S \cap K^C) $$ is a partition of $S$ into disjoint, relative open sets, which are both non-empty. This is not possible because $S$ is connected.