If a patent is filed in country X for a technology that has been existent in country Y for a few years, can they be approved? If yes, say Company A from country X has secured the patent and Company B comes along and "copies" it, Company A sues, is there any defense Company B can provide for themself?
"The technology exists" isn't 100% clear. If it has been available to the public in country X or if documents explaining it have been published in country X in any language, then it can not be legitimately patented by another in country Y. On the other hand, the technology might exist in X and even in country Y but if it is kept a secret everywhere then it can't stop anyone who later invents it themselves from patenting it in either country.
Available to the public, published and kept in secret are all things that a chapter in a book could be written about and do vary from country to country.
Also "company A from country X has secured a patent" is not 100% clear. Patents are territorial.If A has a patent granted by country X and B copies it and makes it, sells it and uses it only in country Y there is no way B gets in trouble over the patent issued by country X. Of course there are nuances to all of this.