Is it grammatically correct to say :
The sun will not rise before an hour.
Or it should be
The sun will not rise in an hour.
In my opinion both sentences are correct with a subtle difference in meaning .
To use the first sentence, you need to append something like has passed to the end of it. This makes the timing of the hour passing event less ambiguous.
The sun will not rise before an hour has passed.
The second sentence is perfectly fine.
I don't think it is ever idiomatic English to use "before" with a period of time. "Before an hour" or "Before three days" always sound to me like a non-native English speaker translating from their own language.
You can use "in", but this often means at the end of the period rather than during the course of the period: which meaning applies depends on several factors, and it may be genuinely ambiguous. So
The sun will rise in an hour.
generally means that the sun will come up one hour from now, not that it will rise some time during the next hour. But
The sun won't rise in an hour.
is more ambiguous. It might be denying that sunrise is one hour from now, or it might be denying that sunrise is earlier than one hour from now.
Some other examples of this subtlety:
He'll come in twenty minutes.
almost certainly means that he is expected at the end of twenty minutes, but
He'll come in the next twenty minutes.
means that he is expected any time during the twenty minutes.
Edit: Points I forgot to make, but have been reminded by other people:
A way to say that something will happen by the end of a period, but not necessarily right at the end, is "within". So The sun will not rise within an hour is clear that I'm saying it won't rise at any time in that hour, while The sun will not rise in an hour might be ambiguous as to whether I mean that, or I mean that it will not rise at the time one hour from now.
While we don't use before with periods of time, we do use it with points in time: The sun won't rise before 8 o'clock is fine.