Is "Which countries is Nicaragua competing with?" grammatically correct?
Your question is very interesting and your doubt valid, but the sentence you quoted is grammatically correct.
Basic statement:
Nicaragua is competing with [certain] countries.
Here Nicaragua is the subject, 'compete' is the verb, 'with' is the preposition and 'countries' is the object.
Basic question form, which you suggested yourself:
With which countries is Nicaragua competing?
I think starting the sentence with "with which" reduces the chance of the reader automatically starting to think of 'countries' as the subject of the sentence.
Another way of writing the same:
Which countries is Nicaragua competing with?
This is your quoted sentence that 'sounds odd' because of the "which countries is" sequence. The earlier sentence was rearranged to place the object "countries" prominently at the front of the sentence.
This type of rearrangement is called 'fronting' as noted by @Janus Bahs Jacquet in comments.
‘Nicaragua’ is the subject of the verb; ‘[which] countries’ is the (fronted) object of the preposition ‘with’. – Janus Bahs Jacquet Aug 17 '13 at 22:21
So what exactly is 'fronting'?
In English grammar, fronting refers to any construction in which a word group that customarily follows the verb is placed at the beginning of a sentence. Also called front-focus or preposing. Fronting is a type of focus strategy often used to enhance cohesion and provide emphasis.
Source: https://www.thoughtco.com/fronting-in-grammar-1690875
If it had been 'country' instead of 'countries' the sentence would have sounded very natural and it would not even have been noticed:
Which country is Nicaragua competing with?
In short it was the unintentionally incongruous juxtaposition of 'countries' with 'is' (rather than the expected plural 'are') that made the sentence sound odd, as already pointed out by @J.R. in comments.
Note that there can be another version of the sentence (also pointed out in the answer of @Ahmed Masud) where 'countries' is actually the subject and "countries are" is the correct construction:
Which countries are competing with Nicaragua?
So if you feel the sentence you quoted might better be rewritten then 2 good ways to rearrange it are
With which countries is Nicaragua competing?
Which countries are competing with Nicaragua?