So I've tried this question for a while now, but can't seem to get an answer. I tried to equate $z$ but don't know how to proceed. Can someone help?
In a $\triangle XYZ$, $\angle XYZ = 90^\circ$. Also $XY= x$, $YZ = y$, and $ZX = z$.
Suppose that $x$, $y$, and $z$ are integers, perimeter $P= 510$, and area $A= kP$, for some prime number $k$. Determine all possible values of $k$.
My solution so far

Just added an Addendum which completes the solution.
Just added analysis to the end of this answer, which improves the lower bound on $z$ from $(z > 170)$ to $(z > 211).$
This is a partial solution (only).
You are given that:
$x,y,z \in \Bbb{Z^+}.$
$x^2 + y^2 = z^2.$
$x + y + z = 510.$
$(1/2) \times (xy) = 510k \implies (xy) = 1020k ~:~k~$ prime.
Then $\displaystyle (510 - z)^2 = (x+ y)^2 = x^2 + y^2 + 2xy = z^2 + 2040k \implies$
$\displaystyle (510)^2 + z^2 - 2(510)z = z^2 + 4(510)k \implies$
$\displaystyle (510)^2 - 2(510)z = 4(510)k \implies$
$$(510) - 2z = 4k \implies 255 - z = 2k.\tag1$$
This is the same formula that the OP reached.
The upper bound of $\displaystyle k \leq 127$ may be routinely improved.
Since $x^2 + y^2 = z^2,$ you know that $x < z$ and $y < z$.
Therefore $\displaystyle 3z > (x + y + z) = 510 \implies z > 170.$
Using equation (1) above, since $z\displaystyle \geq 171, ~~2k \leq (255 - 171) = 84 \implies k \leq 42.$
Therefore, the only candidate values for $k$ are
$\{2,3,5,7,11,13,17,19,23,29,31,37,41\}.$
Personally, I see no alternative to brute force examination of each of the candidate values to determine which ones are viable.
Edit
Analysis may be used to determine a larger minimum value for $z$, which in turn would determine a smaller maximum value for $k$.
Suppose $y = rx, r > 0.$
Then $~~\displaystyle x^2 + r^2x^2 = z^2 \implies x^2 (1 + r^2) = z^2 \implies $
$\displaystyle x = z\frac{1}{\sqrt{1 + r^2}} \implies y = z\frac{r}{\sqrt{1 + r^2}}.$
Then, $~~\displaystyle 510 = (x + y + z) = z\left[\frac{1 + r}{\sqrt{1 + r^2}} + 1\right].$
Therefore, the minimum value for $z$ is determined by determining which value for $(r)$ maximizes
$\displaystyle \frac{1 + r}{\sqrt{1 + r^2}}.$
which is equivalent to determining which value for $(r)$ maximizes
$\displaystyle \frac{(1 + r)^2}{1 + r^2} = \frac{1 + r^2 + 2r}{1 + r^2} = 1 + 2\frac{r}{1 + r^2}.$
The question has therefore been simplified to determining which value for $(r)$ maximizes
$\displaystyle \frac{r}{1 + r^2}.$
Let $~~\displaystyle f(r) = \frac{r}{1 + r^2}.$
Then, $\displaystyle f(1) = (1/2)$.
Suppose that $\displaystyle r = 1-s,$ where $0 < s < 1.$
Then $\displaystyle f(r) = \frac{1 - s}{1 + (1-s)^2} = \frac{1 - s}{1 + 1 - 2s + s^2} < \frac{1 - s}{2 - 2s} = \frac{1}{2}.$
Similarly, suppose that $\displaystyle r = 1+s,$ where $0 < s.$
Then $\displaystyle f(r) = \frac{1 + s}{1 + (1+s)^2} = \frac{1 + s}{1 + 1 + 2s + s^2} < \frac{1 + s}{2 + 2s} = \frac{1}{2}.$
Therefore $\displaystyle f(r) = \frac{r}{1 + r^2}$ obtains a maximum value at $r = 1$.
This implies that the minimum value for $z$ is obtained when $x = y$.
$\displaystyle x = y \implies 2x^2 = x^2 + y^2 = z^2 \implies x = y = z\left(\frac{1}{\sqrt{2}}\right) \implies $
$\displaystyle 510 = x + y + z = z\left(1 + \sqrt{2}~\right).$
Therefore, the minimum value for $z$ is
$\displaystyle \frac{510}{1 + \sqrt{2}} > 211 \implies (2k) < (255 - 211) = 44 \implies k < 22.$
Therefore, the set of candidate values for $k$ has been reduced to
$\{2,3,5,7,11,13,17,19\}.$
Addendum
Completing the solution.
Using the Wikipedia article, the generating function for primitive pythagorean triples is
$$x = m^2 - n^2, ~y = 2mn, ~z = m^2 + n^2 $$
[Constraint-1]:
$\displaystyle \text{where} ~m,n \in \Bbb{Z^+}, ~~m > n, ~~m,n ~~\text{relatively prime},$
$\displaystyle \text{and} ~~m,n ~\text{have different odd/even parity}.$
This implies that all pythagorean triples will have form $$x = t(m^2 - n^2), ~y = 2tmn, ~z = t(m^2 + n^2) ~~:~~ t \in \Bbb{Z^+} \tag2$$
subject to the Constraint-1 restrictions above.
Therefore,
$\displaystyle (510) ~=~ x + y + z ~=~ t[(m^2 - n^2) + 2mn + (m^2 + n^2)]$
$\displaystyle ~= 2t(m^2 + mn) ~=~ 2t(m)(m+n).$
$\displaystyle (2^2 \times 3 \times 5 \times 17 \times k) = 1020k = (xy) = 2t^2(m^2 - n^2)(mn).$
$\underline{\text{Case 1:} ~~x,y,z ~~\text{is a primitive pythagorean triplet}}$
This implies that $t = 1$, which implies that
$\displaystyle (3 \times 5 \times 17) = 255 = (m)(m+n),$
subject to the Constraint-1 restrictions above.
This leads to the following table:
\begin{array}{| r | r | r |} \hline m & m+n & n \\ \hline 1 & 255 & 254 \\ 3 & 85 & 82 \\ 5 & 51 & 46 \\ 17 & 15 & -2 \\ 15 & 17 & 2 \\ 51 & 5 & -46 \\ 85 & 3 & -82 \\ 255 & 1 & -254 \\ \hline \end{array}
Therefore, under the assumption that $(x,y,z)$ is a primitive pythagorean triplet, the only entry in the above table that satisfies Constraint-1 on $m,n$ is $m = 15, n=2$.
This implies that $\displaystyle x,y = 221, 60~$ respectively, which implies that
$\displaystyle (xy) = (60 \times 221) = (1020) \times 13$
and that
$\displaystyle z = \sqrt{(221)^2 + (60)^2} = 229 \implies (x + y + z) = 221 + 60 + 229 = 510.$
Therefore, if $(x,y,z)$ is a primitive pythagorean triplet, the only viable value for $k$ is $(k=13)$ which does generate an acceptable pythagorean triplet.
$\underline{\text{Case 2:} ~~x,y,z ~~\text{is not a primitive pythagorean triplet}}$
This implies that $t > 1$, and
$\displaystyle 1020k = (xy) = 2t^2(mn)(m^2 - n^2)$
which implies that $\displaystyle 510k = t^2(mn)(m^2 - n^2)$
which implies that $\displaystyle 510k = (2 \times 3 \times 5 \times 17 \times k)$ is not square free.
With $(13)$ already verified as a feasible value for prime $k$
the remaining candidate values for $k$ are
$\displaystyle \{2,3,5,7,11,17,19\}.$
This is an opportune moment to split these remaining candidate values of $k$ into two sets:
$$S_1 = \{2,3,5,17\} ~~\text{and}~~ S_2 = \{7,11,19\}.$$
Under the assumption that
$\displaystyle (2 \times 3 \times 5 \times 17 \times k) ~~$ is not square free,
the 3 elements in $S_2$ can be immediately rejected.
Therefore, the elements in $S_1$ are the only elements that remain to be considered.
This leads to the following table:
\begin{array}{| r | r | r | r | r |} \hline (k = t) & (k^2 = t^2) & 510k & \left\{[mn(m^2 - n^2)] = \dfrac{510k}{k^2}\right\} & \left\{[m(m+n)] = \dfrac{510}{2k}\right\}\\ \hline 2 & 4 & 1020 & 255 & 127.5 \\ 3 & 9 & 1530 & 170 & 85 \\ 5 & 25 & 2550 & 102 & 51 \\ 17 & 289 & 8670 & 30 & 15 \\ \hline \end{array}
In the above table, $[k=2 \implies m(m+n) = 127.5]$ is immediately rejected. For the remaining entries, brute force can be avoided by noticing that
$$(mn)(m^2 - n^2) = (m)(m+n)(n)(m-n) \implies $$ $$\frac{(mn)(m^2 - n^2)}{(m)(m+n)} = (n)(m-n).$$
In the above table, in each of the entries, you have that
$\displaystyle (n)(m-n) = \frac{(mn)(m^2 - n^2)}{(m)(m+n)} = 2.$
This implies that both $(n)$ and $(m-n)$ are factors of $(2)$.
This implies that $(m,n)$ must be $\in \{(3,1), (3,2)\}.$
This leads to the following table:
\begin{array}{| r | r | r | r | r | r | r |} \hline (k = t) & (m,n) & x & y & z & (x + y + z) & (xy) \\ \hline 3 & (3,1) & 24 & 18 & 30 & 72 & 432 = 144k \\ 3 & (3,2) & 15 & 36 & 39 & 90 & 540 = 180k \\ 5 & (3,1) & 40 & 30 & 50 & 120 & 1200 = 240k \\ 5 & (3,2) & 25 & 60 & 65 & 150 & 1500 = 300k \\ 17 & (3,1) & 136 & 102 & 170 & 408 & 13872 = 816k \\ 17 & (3,2) & 85 & 204 & 221 & 510 & 17340 = 1020k \\ \hline \end{array}
Therefore, in Case 2, only $k = 17$ satisfies all of the constraints.
Therefore, the only allowable values for $k$ are $(k=13)$ and $(k=17)$.