I can not put the commutative diagram under the frame:
\documentclass{amsart}
\usepackage{latexsym,amsmath}
\usepackage{tabularx, environ}
\usepackage{wasysym,latexsym,amsmath,amssymb,mathrsfs}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{mathtools}
\newcommand{\one}{\mathbf{1}}
\usepackage{scalerel,stackengine}
\usepackage{tikz-cd}
\usepackage{pst-node}
\DeclareMathOperator{\id}{id}
\stackMath
\newcommand\reallywidehat[1]{%
\savestack{\tmpbox}{\stretchto{%
\scaleto{%
\scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\bigwedge\kern-.6pt}%
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG WEDGE
}{\textheight}%
}{0.5ex}}%
\stackon[1pt]{#1}{\tmpbox}%
}
\parskip 1ex
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[theorem]
\newtheorem{remark}{Remark}[theorem]
\newtheorem{question}{Question}[theorem]
\newtheorem{solution}{Solution}[theorem]
\makeatletter
% https://tex.stackexchange.com/a/199244/26355
\newcolumntype{\expand}{}
\long@namedef{NC@rewrite@\string\expand}{\expandafter\NC@find}
\NewEnviron{problem}[2][]{%
\def\problem@arg{#1}%
\def\problem@framed{framed}%
\def\problem@lined{lined}%
\def\problem@doublelined{doublelined}%
\ifx\problem@arg@empty%
\def\problem@hline{}%
\else%
\ifx\problem@arg\problem@doublelined%
\def\problem@hline{\hline\hline}%
\else%
\def\problem@hline{\hline}%
\fi%
\fi%
\ifx\problem@arg\problem@framed%
\def\problem@tablelayout{|>{\bfseries}lX|c}%
\def\problem@title{\multicolumn{2}{|l|}{%
\raisebox{-\fboxsep}{\textsc{\Large #2}}%
}}%
\else
\def\problem@tablelayout{>{\bfseries}lXc}%
\def\problem@title{\multicolumn{2}{l}{%
\raisebox{-\fboxsep}{\textsc{\Large #2}}%
}}%
\fi%
\bigskip\par\noindent%
\renewcommand{\arraystretch}{1.2}%
\begin{tabularx}{\textwidth}{\expand\problem@tablelayout}%
\problem@hline%
\problem@title\[2\fboxsep]%
\BODY\\problem@hline%
\end{tabularx}%
\medskip\par%
}
\makeatother
\newenvironment{subproof}[1][\proofname]{%
\renewcommand{\qedsymbol}{$\blacksquare$}%
\begin{proof}[#1]%
}{%
\end{proof}%
}
\newcolumntype{\expand}{}
\long@namedef{NC@rewrite@\string\expand}{\expandafter\NC@find}
\NewEnviron{problem}[2][]{%
\def\problem@arg{#1}%
\def\problem@framed{framed}%
\def\problem@lined{lined}%
\def\problem@doublelined{doublelined}%
\ifx\problem@arg@empty%
\def\problem@hline{}%
\else%
\ifx\problem@arg\problem@doublelined%
\def\problem@hline{\hline\hline}%
\else%
\def\problem@hline{\hline}%
\fi%
\fi%
\ifx\problem@arg\problem@framed%
\def\problem@tablelayout{|>{\bfseries}lX|c}%
\def\problem@title{\multicolumn{2}{|l|}{%
\raisebox{-\fboxsep}{\textsc{\Large #2}}%
}}%
\else
\def\problem@tablelayout{>{\bfseries}lXc}%
\def\problem@title{\multicolumn{2}{l}{%
\raisebox{-\fboxsep}{\textsc{\Large #2}}%
}}%
\fi%
\bigskip\par\noindent%
\renewcommand{\arraystretch}{1.2}%
\begin{tabularx}{\textwidth}{\expand\problem@tablelayout}%
\problem@hline%
\problem@title\[2\fboxsep]%
\BODY\\problem@hline%
\end{tabularx}%
\medskip\par%
}
\makeatother
\newenvironment{subproof}[1][\proofname]{%
\renewcommand{\qedsymbol}{$\blacksquare$}%
\begin{proof}[#1]%
}{%
\end{proof}%
}
\usepackage{tikz-cd}
\begin{document}
\begin{problem}[framed]{Question 2}
%Task: & Define a new ``problem'' environment. \
Problem: & Show that any two terminal objects are isomorphic. Specifically, if $\mathbf{1}$ and $\mathbf{1}^{\prime}$ are both terminal objects, show that there are arrows $f: \mathbf{1} \rightarrow \mathbf{1}^{\prime}$ and $g: \mathbf{1}^{\prime} \rightarrow \mathbf{1}$ such that $g \circ f=\mathrm{id}{1}$ and $f \circ g=\mathrm{id}{1}$. This is what it means for two objects to be isomorphic in a category.\
Solution: & As, $\mathbf{1},\mathbf{1}^{\prime}$ are terminal objects. From $\mathbf{1} \to \mathbf{1}^{\prime}, \mathbf{1} \to \mathbf{1}$ we have a unique map so are from $\mathbf{1}^{\prime} \to \mathbf{1}, \mathbf{1}^{\prime}\to \mathbf{1}^{\prime}$. Then we have maps $f \circ g: \mathbf{1}^{\prime} \to \mathbf{1}^{\prime}$ and $g \circ f: \mathbf{1} \to \mathbf{1}.$ Now $id|{\mathbf{1}^{\prime}}:\mathbf{1}^{\prime} \to \mathbf{1}^{\prime}$ and $id|{\mathbf{1}}:\mathbf{1} \to \mathbf{1}$ are also maps then $g \circ f=id_{\mathbf{1}}$ and $f \circ g=id_{\mathbf{1}^{\prime}}.$
\end{problem}
\begin{problem}[framed]{Question 5}
%Task: & Define a new ``problem'' environment. \
Problem: & "Let $\mathbf{C}$ be a category with terminal object $\mathbf{1}$. Let $X$ be an object of $\mathbf{C}$. We will prove that $X \times 1$ is isomorphic to $X$.
(a) Because $X \times 1$ is the product of $X$ and 1 , it comes with two arrows. Describe them by stating their domain and codomains.
(b) There is another object with arrows to both $X$ and 1 . What is it? What are the arrows?
(c) Use the existence property of products to find a right-inverse u for the arrow $\pi_{X}: X \times \mathbf{1} \rightarrow X .$
(d) Now we want to show that $u$ is a left-inverse to $\pi_{X}$ as well. To that end, name one arrow $f: X \times \mathbf{1} \rightarrow X \times \mathbf{1}$ so that the following diagram commutes, meaning that $\pi_{X} \circ f=\pi_{X} .$
\end{problem}
[
\begin{tikzcd}[row sep=huge]
& X\times \textbf{1}\ar[dl,"\pi_{X}",swap,sloped] \ar[dr,"",sloped] \ar[d,,"{f}" description] & \
X & X\times \textbf{1}\ar[l,"\pi_{X}"] \ar[r,"",swap] & \textbf{1}
\end{tikzcd}
]
\begin{problem}[framed]{}
Problem: & (e) There is another arrow $X \times 1 \rightarrow X \times 1$ so that the above diagram commutes. What is it? (Hint: it's a composition of two other arrows)
(f) Use the uniqueness property of products to conclude that the two arrows from parts (d) and (e) must be equal.
(g) Conclude that the arrow $u$ from part $(c)$ is a left-inverse to $\pi_{X}: X \times 1 \rightarrow X$ as well as a right inverse.
(h) Conclude that $u$ is an isomorphism, and $X \cong X \times 1$."\
Solution: & a) Domain and codomain of $\pi_X$ are $ X\times \textbf{1}$ and $X$ resp. Domain and codomain of $\pi_{\textbf{1}}$ are $ X\times \textbf{1}$ and $\textbf{1}$ resp.
b) Another object is $X$ and the arrows $X \to X$ is identity and $X \to \textbf{1}$ is the unique map corresponding to the terminal object.
c) If we replace $A$ by $X$ and $B$ by $\textbf{1}, \rho_A=id, \pi_A=\pi_X$ in the figure of definition 2,
\end{problem}
[
\begin{tikzcd}[row sep=huge]
& X\ar[dl,"id",swap,sloped] \ar[dr,"\rho_{B}",sloped] \ar[d,dashed,"{u}" description] & \
X & X \times \textbf{1}\ar[l,"\pi_{X}"] \ar[r,"\pi_{\textbf{1}}",swap] & \textbf{1}
\end{tikzcd}
]
\begin{problem}[framed]{}
Solution: &we'll get the unique map from $u:X \to X \times \mathbf{1} $ s.t $\pi_X \circ u=id_X$. Hence we get the right-inverse $\pi_A$ of $u$. Observe that $u: X \to X \times \mathbf{1}$ is the inclusion map here i.e. $u(x)={x}\times \mathbf{1}.$
d) %We can see that $u \circ \pi_X({x} \times \mathbf{1})=u(x)={x} \times \mathbf{1}$, i.e., $$X \times \mathbf{1} \stackrel{\pi_X}{\longrightarrow} X \stackrel{u}{\longrightarrow} X \times \mathbf{1}
%$$ is the identity map. Hence $u$ is also a left-inverse of $\pi_X$.
We name $f=id_{X \times \mathbf{1}}.$
e) $u \circ \pi_X$ is another arrow $X \times 1 \rightarrow X \times 1$ so that $\pi_x \circ (u \circ \pi_X)=(\pi_x \circ u) \circ \pi_X=(id) \circ \pi_X=\pi_X$ hence, the above diagram commutes.
f) From Universal property of product we get $u \circ \pi_X=id_{X \times \mathbf{1}}.$
g) $u$ is a left inverse of $\pi_X.$
h) $X \cong X \times \mathbf{1}.$
\end{problem}
\end{document}
See qn 2 and then qn 5. You will realize what is looking odd here. I have to break the frame every time I want to include a diagram.

ampersand replacement=\&option to thetikzcdenviroment and to use\&instead of&in the body. – egreg Dec 07 '21 at 21:49