Here is a proposal using the nicematrix
package. Unfortunately, as far as I could see, their nice dotted lines are not in some styles that can be used by the user for their own annotations, so I had to redo it using a variant of this answer.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
line width=1pt,
dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
shorten >=0.3em,shorten <=0.3em},
Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I &0 &\Cdots &0\\
0 & I &\Ddots &\Vdots\\
\Vdots &\Ddots &I &0\\
0 &\Cdots &0 &I
\end{pNiceArray}
\]
and
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2) -- (2-3);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0 &\Cdots &0 &I\\
\Vdots & &I &0\\
0 &I & &\Vdots\\
I &0 &\Cdots &0
\end{pNiceArray}
\]
\end{document}

Or a version with parallel dotted lines.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
line width=1pt,
dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
shorten >=0.3em,shorten <=0.3em},
Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I &0 &\Cdots &0\\
0 & I &\Ddots &\Vdots\\
\Vdots &\Ddots &I &0\\
0 &\Cdots &0 &I
\end{pNiceArray}
\]
and
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2.30) -- (2-3.-150);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0 &\Cdots &0 &I\\
\Vdots & &I &0\\
0 &I & &\Vdots\\
I &0 &\Cdots &0
\end{pNiceArray}
\]
\end{document}
Or without nicematrix
.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,mathdots}
\begin{document}
\[A=
\begin{pmatrix}
I &0 &\cdots &0\\
0 & I \smash{\makebox[0pt][l]{\;\raisebox{-0.8em}{$\ddots$}}} &\ddots &\vdots\\
\vdots &\ddots &I &0\\
0 &\cdots &0 &I
\end{pmatrix}
\]
and
\[B=
\begin{pmatrix}
0 &\cdots &0 &I\\
\vdots & \iddots &I &0\\
0 &I\smash{\makebox[0pt][l]{\;\raisebox{0.8em}{$\iddots$}}} & \iddots &\vdots\\
I &0 &\cdots &0
\end{pmatrix}
\]
\end{document}
