Why do authors invent fictional countries on earth in their novels and how do you keep the lie up? For example, if you talk about neighboring countries, don't these neighboring countries also have to be fictional so that there's no logic gap? If you were to use real countries then the fictional countries or country would be out of place and you wouldn't be able to really locate them, or some conflicts would arise because it could be next to countries that cannot be neighboring it, so how do you deal with these issues?
If you want to have a setting, but reality comes with a lot of baggage, then you need to create a new place. This can be LIKE a real place, but just a bit off so you can justify things that simply don't exist. But the point here is to skip the baggage of the real place while capturing the spirit of a real place.
In most stories, I see this used either when the author has a specific country in mind that doesn't perfectly align with their needs, or the deliberately want to keep it vague. Often, the approximate identification of the country is given, like Sokovia (think Avengers: age of Ultron) is clearly some kind of small nation in Europe, but they never discuss neighbors. They never discuss neighbors, that is, unless the neighbors are also equally fictional. So two adjacent fictional countries can have all the detail you want, but any discussion of outside states immediately becomes fuzzy.
Alternatively, the place can be specific, but non-existent like an island where there is no island. This avoids the need to be quite as vague, but the lack of hard borders means these kind of subtle interactions are avoided, allowing people to focus on the point of the story and not the nitty-gritty of details.
The key is to avoid discussing exact position. You give just enough detail to evoke the kind of atmosphere you want, while never specifying the details. This is a pretty easy suspension of disbelief.
Kinda simple, to avoid offending people. Take DWKraus his example of Sokovia, it is most likely inspired by Slovakia(or a other eastern European nation). The nation is depicted as pretty much a third world country and in several episodes/movies in the MCU it is also implied that it had a corrupt government that wasn't above killing people.
If they had actually taken a real life name it would have offended a lot of people from that country. The movie would then partially become a political statement what leads to discussions that you might want to avoid.
Even if the depiction is positive it can be seen as offensive due to it being historical of factually inaccurate... like a nation suddenly having a royal family or have weird traditions, or lack traditions that are important to them.
It also gives you a lot more options on how you will depict them, take Wakanda for example... in no way would anyone view a current African nation as a world power...but by making a new nation, and give it such a backstory it becomes possible in that reality.
Stay away from maps/neighbors or invent new neighbors. Instead of a single country make a small country cluster that has a shared history together. This way you can have a history of conflict without dragging real life nations in to it. Easiest way would be to make a new (small) continent, somewhere in the ocean where they can do their own thing without involving the rest of the world.
Sometimes the author wanted to set the country in a location that is akin to a region but doesn't want to offend a potential market, so make the country fictional to allow free reign without offense (The fictional Caribbean nation Val Verde pops up in lots of works, most famously Commando, Predator, and Die Hard 2 mostly because the screen writer had Caribbean family and wanted more films set there but didn't want to offend nations in volatile political situations.).
Other nations feature the ruler or higher political office holder as a character, such as Wakanda or Latvaria, both Marvel nations whose rulers are quite active superheroes or villains respectively (Black Panther and Doctor Doom). DC has a slew of nations in the middle east with a surprisingly complicated regional politics between them (especially in the 2000s onward when the U.S.-Middle East Relations was much more prominent in media and comics began to add some political stories. The complicated political relations is mostly because writers will use them for all sorts of stories featuring the heroes in the middle East.). It should be noted that Marvel lacks major fictional nations as most of their heroes work around NYC and the fictional nations they do have are by and large have dignitaries come to town (The U.N. was a new thing when Marvel's biggest lines were getting discussed.).
Other reasons are to set up a government system to experiment with new forms of governance (Utopia and Atlantis were originally used as social commentary societies, and the modern browser based game NationStates allows the user to create their own fictional country and decide on policy).
A final reason is that, well, since World War II, the map of nations has been confusing with new nations rising and breaking apart all the time from 1945 onwards, not helped by the Cold War Powers using them for proxy wars or power plays and continents we think have stable politics in the modern era were only recent developments (Eastern Europe was the subject of a lot of border changes in the early 90s following the collapse of the Soviet Union, Africa's decolonization left it with the largest amount of nations for a single continent, South and Central America were quite prone to military dictatorships because the U.S. did not like Communism on their side of the globe, and "Unrest in the Middle East" has been a thing since before Jesus.).
Other times nations are used as fictional counterparts on an alternate world map as a whole (happens a lot in table top RPG settings, where they need to fill in space on the world map and copying real world cultures is really easy). Or to explain wars we wouldn't see to day (the Ace Combat series uses a fictional war to get players into modern jet warfare because real world dog fighting and modern arms wars are not as commons since nukes were added. Ace Combat lore is that Nukes were never invented and other superweapons take their place.). And then others are used to get a general feel of a place in an open world setting but hold their own stories. Rockstar video games are very good at mimicking real world places with a fictional spin on them, usually using fictional U.S. Cities and States modeled after real ones (Liberty City/State is NYC/NY, San Andreas is California with a bit of Vegas area Nevada, Vice City is Miami, although it's flat out stated that it's in Florida, likely because as over the top as Rockstar's stereotypes are, even they got to admit defeat in trying to go over the top on Florida Man's native home.).
I came up with a fictional continent that is off the coast of California. It is a small island, so all I had to do was look at a map and place it to where it is far enough away from California so you cannot see it from the coast and make sure it is also far away from the other real life countries. I choose to do it because I can do whatever I want on that island. I can invent my own laws, or customs and everything. It feels more personal to me to create a new continent rather then just change or replace an existing one. I can also write and see how people from other continents react to it, because the island remained hidden for years and it was only recently founded.