05AB1E, 15 14 bytes
∞+.ΔαD3mαy¿yp+
Inspired by @Giuseppe's Gaia answer, so make sure to upvote him as well!
Try it online or verify all test cases.
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
+ # Add the (implicit) input `n` to each: [n+1,n+2,n+3,...]
.Δ # Find the first `n+b` which is truthy for:
α # Take the absolute difference with the (implicit) input: [1,2,3,...]
D # Duplicate this `b`
3m # Cube it: b³
α # Take the absolute difference with the `b` we've duplicated: |b-b³|
y¿ # Get the greatest common divisor with the current `b+n`: gcd(|b-b³|,b+n)
yp # Check whether `b+n` is a prime number (1 if prime; 0 if not)
+ # Add them together: gcd(|b-b³|,b+n)+isPrime(b+n)
# (NOTE: only 1 is truthy in 05AB1E)
# (after which the result is output implicitly as result)