The given matrix equation implies that the minimal polynomial of $A$ divides $f(x):=p^2 x^{p^2} - q^2 x^{q^2} - r^2$. It follows that $A$ can be constructed as a block diagonal matrix $\begin{bmatrix} C_g & 0\\ 0 & I_{n-d} \end{bmatrix}$ for any monic divisor $g(x)\mid f(x)$ of degree $d:=\deg g(x)\leq n$, where $C_g$ is the companion matrix of $g(x)$.
Here is a sample code that constructs and prints such matrices:
def compA(n,p,q,r):
assert p^2 == q^2 + r^2
R.<x> = PolynomialRing(ZZ)
f = p^2*x^(p^2) - q^2*x^(q^2) - r^2
for g in divisors(f):
if g.degree()>n or not g.is_monic():
continue
A = block_diagonal_matrix(companion_matrix(g), identity_matrix(n-g.degree()))
print(A)
More generally, $A$ can be taken as a block diagonal matrix with blocks $C_{g_1}, \dots, C_{g_k}$, where each $g_i(x)$ is a monic divisor of $f(x)$, and $\sum_{i=1}^k \deg g_i(x) = n$. Matrices similar to such $A$ will also satisfy the given matrix equation.
Please help..here p,q,r,n are all given to us..
How are graphs related to this matrix equation?
If $A$ satisfies $A^{p^2} = A^{q^2} = I_n$, then that works, e.g. if $A^2=I_n$ and $p$ and $q$ are both even. If you want Sage to solve the general problem, then you can write $A$ with all symbolic entries and try to solve the resulting $n^2$ Diophantine equations. If $n$, $p$, or $q$ are large, I think this will be very difficult. What values do you have in mind?
but p and q both can not be even since r is given to be odd and they form Pythagorean triple
Yes, you're right, but the rest of my comment still applies. For example if $A^3=I$ and both $p$ and $q$ are divisible by 3. Or do you want to assume that $p$, $q$, and $r$ are relatively prime? In any case, if you imagine that $A$ has indeterminate entries and $p=5$, then you will have polynomial equations of degree 25. How would you hope to solve this?