foldr is defined as
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)
So when you plug in the arguments you would get
foldr getNextPrime [2] [3,5..]
= getNextPrime 3 (foldr getNextPrime [2] [5,7..])
= getNextPrime 3 (getNextPrime 5 (foldr getNextPrime [2] [7,9..])
etc...
For this to lazily produce values (what you want when dealing with infinite lists) then getNextPrime needs to lazily produce values. Looking at the definition of getNextPrime, primes ++ [n], meaning you're appending a value onto the end of your primes list, but primes for getNextPrime 3 is getNextPrime 5 (foldr getNextPrime [2] [7,9..]). But then primes for getNextPrime 5 is getNextPrime 7 (foldr getNextPrime [2] [9,11..]), etc, etc. You never actually are able to produce a normal form value for primes, it's always a chain of computations that never return.
Another way to look at this is to look at this is to replace getNextPrime with an operator, let's call it .:
foldr (.:) [2] [3,5..9]
= 3 .: (5 .: (7 .: (9 .: [2])))
(this is why it's called a right fold, the parens are nested to the right)
This works great for using : in foldr:
foldr (:) [2] [3,5..9]
= 3 : (5 : (7 : (9 : [2])
because : just builds a new data structure, and the first element of this data structure can be inspected without calculating the rest of the structure. But .: isn't so nice, it first needs to calculate x1 = 9 .: [2], then x2 = 7 .: x1, then x3 = 5 .: x2, and finally 3 .: x3. For [3,5..] instead, you never can calculate the last call of something .: [2], but haskell keeps trying to compute it and that blows the stack.