[proofplan]
We prove definability formula by formula. Fix $\varphi(x;y)$ and consider the set of parameters $b \in M^{|y|}$ for which $\varphi(x;b)$ belongs to the type $p$. Stability says that $\varphi$ has no order property, and the local definability theorem for stable formulas converts this absence of order into definability of the $\varphi$-part of any type over a model. Applying this local result to every formula gives the required definitional scheme for $p$ over $M$.
[/proofplan]
[step:Fix one formula and isolate the corresponding trace of the type]
Fix a formula $\varphi(x;y)$. Define the parameter set
\begin{align*}
X_p^\varphi := \{b \in M^{|y|} : \varphi(x;b) \in p\}.
\end{align*}
This is a subset of $M^{|y|}$. To prove that $p$ is definable over $M$, it is enough to show that for each $\varphi(x;y)$ there is an $M$-formula $d_p\varphi(y)$ defining $X_p^\varphi$ in $M$, meaning
\begin{align*}
X_p^\varphi = \{b \in M^{|y|} : M \models d_p\varphi(b)\}.
\end{align*}
[/step]
[step:Use stability to obtain local definability for the fixed formula]
Since $T$ is stable, no formula of $T$ has the order property. In particular, the fixed formula $\varphi(x;y)$ is stable.
Let $S_\varphi(M)$ denote the space of complete $\varphi$-types over $M$, meaning maximal consistent choices, for all $b \in M^{|y|}$, of exactly one formula from the pair $\varphi(x;b)$ and $\neg\varphi(x;b)$.
We now use the local definability theorem for stable formulas: if $\varphi(x;y)$ is stable, $M \models T$, and $q \in S_\varphi(M)$ is a complete $\varphi$-type over $M$, then there is a formula $d_q\varphi(y)$ with parameters from $M$ such that, for every $b \in M^{|y|}$,
\begin{align*}
M \models d_q\varphi(b)
\quad \Longleftrightarrow \quad
\varphi(x;b) \in q.
\end{align*}
(citing a result not yet in the wiki: Local Definability Theorem for Stable Formulas)
The $\varphi$-fragment of $p$,
\begin{align*}
p|_\varphi := \{\varphi(x;b) : b \in M^{|y|},\ \varphi(x;b) \in p\}
\cup
\{\neg\varphi(x;b) : b \in M^{|y|},\ \varphi(x;b) \notin p\},
\end{align*}
is a complete $\varphi$-type over $M$, because $p$ is a complete type over $M$ and therefore decides each instance $\varphi(x;b)$ with $b \in M^{|y|}$. Applying the local definability theorem to $q := p|_\varphi$, we obtain an $M$-formula $d_p\varphi(y)$ such that
\begin{align*}
M \models d_p\varphi(b)
\quad \Longleftrightarrow \quad
\varphi(x;b) \in p
\end{align*}
for every $b \in M^{|y|}$.
[guided]
We focus on a single formula $\varphi(x;y)$ because definability of a complete type is a scheme: one definition is required for each formula. The relevant object is not the whole type at once, but the subset of parameters
\begin{align*}
X_p^\varphi := \{b \in M^{|y|} : \varphi(x;b) \in p\}.
\end{align*}
If this set is definable in $M$ for every $\varphi$, then the collection of the defining formulas is exactly the definitional scheme for $p$.
The hypothesis that $T$ is stable means that no formula has the order property. Hence the particular formula $\varphi(x;y)$ is stable. Let $S_\varphi(M)$ denote the space of complete $\varphi$-types over $M$: an element of $S_\varphi(M)$ is a maximal consistent choice, for each $b \in M^{|y|}$, of exactly one of $\varphi(x;b)$ and $\neg\varphi(x;b)$. The local definability theorem for stable formulas applies precisely in this situation: for a stable formula $\varphi(x;y)$, every complete $\varphi$-type over a model is defined by a formula over that model.
We must verify that the object to which we apply the local theorem is an element of $S_\varphi(M)$. Define
\begin{align*}
p|_\varphi := \{\varphi(x;b) : b \in M^{|y|},\ \varphi(x;b) \in p\}
\cup
\{\neg\varphi(x;b) : b \in M^{|y|},\ \varphi(x;b) \notin p\}.
\end{align*}
For each $b \in M^{|y|}$, the completeness of $p$ implies that exactly one of $\varphi(x;b)$ and $\neg\varphi(x;b)$ belongs to $p$. Therefore $p|_\varphi$ decides every instance of $\varphi$ over $M$, and it is consistent because it is contained in the complete type $p$. Thus $p|_\varphi \in S_\varphi(M)$.
Applying the local definability theorem to $p|_\varphi$, we obtain an $M$-formula $d_p\varphi(y)$ satisfying
\begin{align*}
M \models d_p\varphi(b)
\quad \Longleftrightarrow \quad
\varphi(x;b) \in p|_\varphi.
\end{align*}
By the definition of $p|_\varphi$, the right-hand side is equivalent to $\varphi(x;b) \in p$. Hence, for every $b \in M^{|y|}$,
\begin{align*}
M \models d_p\varphi(b)
\quad \Longleftrightarrow \quad
\varphi(x;b) \in p.
\end{align*}
This is exactly the desired definition of $X_p^\varphi$ over $M$.
[/guided]
[/step]
[step:Assemble the local definitions into a definitional scheme]
The preceding step applies to an arbitrary formula $\varphi(x;y)$. Therefore, for every formula $\varphi(x;y)$, there exists an $M$-formula $d_p\varphi(y)$ such that, for all $b \in M^{|y|}$,
\begin{align*}
M \models d_p\varphi(b)
\quad \Longleftrightarrow \quad
\varphi(x;b) \in p.
\end{align*}
Thus the assignment
\begin{align*}
\varphi(x;y) \longmapsto d_p\varphi(y)
\end{align*}
is a definitional scheme for $p$ over $M$. Hence $p$ is definable over $M$.
[/step]