I think, from almost line 1 of what you did, you don't understand double precision arithmetic, and that will cause everything you do in this enterprise to fail.
z = -2 + (10^28 + 501675.8)*1i;
OOPS. You did it right there. Mistake 1. And everything thereafter will fail, or at least be suspect, because that number is not what you think it is.
A complex number, thus what you have in z, is just two doubles, the real and imaginary parts. Now look at what you wrote in the imaginary part:
10^28 + 501675.8
so you are adding 501675.8 to a number on the order of 1e28. What is eps(1e28)?
eps gives you the distance from 1e28, and the nest larger number you can store in a double. You can think of it as effectively the smallest number you can add to 1e28, and get a different result.
Trying to add a number smaller than 2.19e12 to 1e28, this will get you nowhere. In fact, try this:
(1e28 + 501675.8) == 1e28
Do you see that anything you now do with z is going to be potentially mathematical gibberish, since z is not what you think it is?
What else? Lets see.
gamma = 0.57721566490153286060651209;
Most of the digits in that number are useless, since MATLAB will only be able to store the first 16 digits or so as a double. (And even worse, you just overloaded the highly useful function gamma, so the gamma function will not work for you, in case you need it at some point. Don't name variables in a way that overloads existing function names. You will be sorry soon, and then you will be asking on Answers how to make the gamma function work.)
Until you understand that a double has limits in what it can do, you are wasting your time. That is not to say that what you want to do is a waste of imte. But you need to learn to use computational tools properly, else nothing you do will succeed.
So, COULD you do anything with this computation, even if using high precision tools? Possibly. I won't even try to get into that argument. But you MIGHT conceivably then have a chance, using syms and vpa. Even at that, you will need to learn how to work with high precision tools, as it is very easy to still have a problem, if you mix numbers that are entered into MATLAB as doubles, and then turn them into syms.
There are other things you do, that are just a bit silly, not making use of the tools in MATLAB.
function p = smallest_prime_factor(n)
So, a loop to find the smallest prime factor? What does this do?
smallestPrimeFactor = @(n) min(factor(n));
Learn to use the tools already in MATLAB. I suppose that might even extend to learning to use the function psi. But you might not want to go that far, apparently trying to do at least that piece on your own.
lookfor digamma
psi - Digamma and polygamma functions
sym.psi - Digamma function