Sure it's grammatically correct. There are many cases where a word can occur twice in a row and make complete sense, especially when the word is being used with two different definitions. "After fixing twenty mistakes, Sally had had enough." "Bob saw that that was not the right answer." "I got lost because I turned right too soon, but then I circled around and made the right right turn." And of course if you try hard you can come up with crazy examples, like the ever-popular "Buffalo" sentence. (I know that was quoted on here somewhere.)
In most cases where a word is used twice in a row people read it without noticing. If you think in a given case it might be confusing, then sure, find a way to re-word it.