I'm reading about Dirichlet problem and Brownian motion in these notes, i.e.,
Fact. Let $D$ be an open and bounded domain in $\mathbb{R}^n$ and $\partial D$ be its (smooth) boundary. Let $h \in \mathcal{C}(\partial D)$. Then there exists a unique function $u \in \mathcal{C}^2(D)$ such that $$ \begin{cases} \Delta u(\underline{x})=0, & \forall \underline{x} \in D, \\ u(\underline{x})=h(\underline{x}), & \forall \underline{x} \in \partial D . \end{cases} \quad (\star) $$
Remark. The function $u$ takes values in $\mathbb{R}\left(\right.$ not in $\left.\mathbb{R}^n\right)$.
Stochastic representation of the solution. Let $\underline{B}^{\underline{x}}$ be an $n$-dimensional Brownian motion starting at point $\underline{x} \in D$ at time $t=0$ (i.e., $\underline{B}_t^{\underline{x}}=\underline{x}^x+\underline{B}_t$, where $\underline{B}$ is a standard $n$-dimensional Brownian motion). Let also $$ \tau=\inf \left\{t>0: \underline{B}_t^{\underline{x}} \notin D\right\} $$ be the first exit time of $\underline{B}^{\underline{x}}$ from the domain $D ; \tau$ is a stopping time. Notice also that $\underline{B}_\tau^{\underline{x}} \in \partial D$.
Proposition 6.5. The solution of $(\star)$ reads $$ u(\underline{x})=\mathbb{E}(h(\underline{B}_\tau^\bar{x})), \quad \forall \underline{x} \in D . $$
Proof.
Let us first show that the process $(u(\underline{B}_t^{\underline{x}}), 0 \leq t \leq \tau)$ is a martingale. By the multidimensional Ito-Doeblin formula, we have $$ \begin{aligned} u\left(\underline{B}_t^{\underline{x}}\right)-u\left(\underline{B}_0^{\underline{x}}\right) & =\sum_{i=1}^n \int_0^t u_{x_i}^{\prime}\left(\underline{B}_s^{\underline{x}}\right) d B_s^{(i)}+\frac{1}{2} \int_0^t \Delta u\left(\underline{B}_s^{\underline{x}}\right) d s \\ & =\sum_{i=1}^n \int_0^t u_{x_i}^{\prime}\left(\underline{B}_s^{\underline{x}}\right) d B_s^{(i)}, \end{aligned} $$ since $\Delta u(\underline{x})=0, \forall \underline{x} \in D$ and $\underline{B}_s^{\underline{x}} \in D, \forall s \leq \tau$.
Applying therefore the optional stopping theorem, we obtain $$ u(\underline{x})=\mathbb{E}\left(u\left(\underline{B}_0^x\right)\right)=\mathbb{E}\left(u\left(\underline{B}_\tau^{\underline{x}}\right)\right)=\mathbb{E}\left(h\left(\underline{B}_\tau^{\underline{x}}\right)\right), $$ where the third equality holds since $u(\underline{x})=h(\underline{x})$ on $\partial D$ and $\underline{B} \underline{\tau} \in \partial D$.
Because $\tau$ is random, I could not make sense of the sentence "$(u(\underline{B}_t^{\underline{x}}), 0 \leq t \leq \tau)$ is a martingale". Could you elaborate on this point?