[proofplan]
We apply the Leibniz formula and show that the identity permutation is the only permutation contributing a nonzero term. For every $\sigma \neq \operatorname{id}$, there exists an index $k$ with $\sigma(k) \neq k$, and the triangularity condition forces $A_{k,\sigma(k)} = 0$, killing the entire product. The result then follows immediately.
[/proofplan]
[step:Expand the determinant via the Leibniz formula and identify the only surviving term]
The Leibniz formula gives
\begin{align*}
\det A = \sum_{\sigma \in S_n} \operatorname{sgn}(\sigma) \prod_{k=1}^{n} A_{k,\sigma(k)}.
\end{align*}
We treat the upper triangular case; the lower triangular case is analogous (with the inequality reversed).
Suppose $A$ is upper triangular, so $A_{ij} = 0$ whenever $i > j$. For a permutation $\sigma \in S_n$, the product $\prod_{k=1}^{n} A_{k,\sigma(k)}$ is nonzero only if $A_{k,\sigma(k)} \neq 0$ for every $k \in \{1, \dots, n\}$. The upper triangularity condition requires $\sigma(k) \geq k$ for each factor to be (potentially) nonzero.
[claim:The only permutation satisfying $\sigma(k) \geq k$ for all $k$ is $\sigma = \operatorname{id}$]
Suppose $\sigma \in S_n$ satisfies $\sigma(k) \geq k$ for all $k \in \{1, \dots, n\}$. Summing over all $k$:
\begin{align*}
\sum_{k=1}^{n} \sigma(k) \geq \sum_{k=1}^{n} k.
\end{align*}
Since $\sigma$ is a bijection on $\{1, \dots, n\}$, the left-hand side equals $\sum_{k=1}^{n} k$ as well. Therefore equality holds, which forces $\sigma(k) = k$ for every $k$. (If any single inequality were strict, the total sum would exceed $\sum_{k=1}^{n} k$, contradicting the bijectivity of $\sigma$.)
[/claim]
[proof]
Provided in the claim statement above.
[/proof]
Therefore the only nonzero term in the Leibniz sum comes from $\sigma = \operatorname{id}$, which has $\operatorname{sgn}(\operatorname{id}) = 1$:
\begin{align*}
\det A = 1 \cdot \prod_{k=1}^{n} A_{k,k} = \prod_{i=1}^{n} A_{ii}.
\end{align*}
[guided]
We start from the Leibniz formula:
\begin{align*}
\det A = \sum_{\sigma \in S_n} \operatorname{sgn}(\sigma) \prod_{k=1}^{n} A_{k,\sigma(k)}.
\end{align*}
Consider the upper triangular case: $A_{ij} = 0$ whenever $i > j$. For a term in the Leibniz sum to be nonzero, we need every factor $A_{k,\sigma(k)}$ to be nonzero. Since $A_{k,\sigma(k)} = 0$ when $k > \sigma(k)$ (by upper triangularity), we require $\sigma(k) \geq k$ for all $k$.
Which permutations satisfy $\sigma(k) \geq k$ for every $k$? Since $\sigma$ is a bijection on $\{1, \dots, n\}$, we have $\sum_{k=1}^{n} \sigma(k) = 1 + 2 + \cdots + n$. But the constraint $\sigma(k) \geq k$ gives $\sum_{k=1}^{n} \sigma(k) \geq \sum_{k=1}^{n} k$. Since both sides equal $n(n+1)/2$, equality must hold, which means $\sigma(k) = k$ for every $k$. If even one inequality were strict --- say $\sigma(k_0) > k_0$ --- then the sum would strictly exceed $n(n+1)/2$, contradicting bijectivity. So $\sigma = \operatorname{id}$ is the unique permutation with all factors potentially nonzero.
The identity permutation contributes $\operatorname{sgn}(\operatorname{id}) \prod_{k=1}^{n} A_{k,k} = \prod_{k=1}^{n} A_{k,k}$. Every other permutation contributes $0$. Therefore
\begin{align*}
\det A = \prod_{i=1}^{n} A_{ii}.
\end{align*}
The lower triangular case is identical with the inequality reversed: $A_{ij} = 0$ when $i < j$ forces $\sigma(k) \leq k$ for all $k$, and the same sum argument gives $\sigma = \operatorname{id}$.
The diagonal case follows as an immediate corollary: a diagonal matrix is both upper and lower triangular, so the result applies.
[/guided]
[/step]