It feels like answers come "from outer space" or "from God" but it's really just a highly optimized and efficient part of the brain for a very specific function. For that narrow function your brain has an effective IQ of something like 2000. As our brains have a much lower average IQ, we don't have the context to understand how we found the answer so we experience it and describe it as intuition.
If our entire brain operated at an IQ of 2000, we wouldn't experience it as intuition or a flash of genius, we would just say "I figured it out".
What I have read about Ramanujan sounds like he had some form of high functioning savant syndrome. https://en.wikipedia.org/wiki/Savant_syndrome