Some people blame the EU`s policy for leading to the bankruptcy of the Polish shipyards.
I think it's worth discussing the shipyards as part of the bigger picture. They essentially operated within the Communist planning system - Poland imported cheap iron ore from the Soviet Union, produced steel, then used it to build ships that were then sold to the Soviet Union. Fair enough, it provided large amounts of employment under Communism, but it made very little economic sense.
The system changes in the late 1980's, as the Soviet Union no longer has the means of selling iron ore cheaply, nor does it need ships. It would take an essay to explain what exactly happened, but the end result was that Gdańsk in particular drowned under a mountain of debt and bad management. The problem was that in all three shipyards, they were more than just shipyards - they operated medical centres, kindergartens, hotels, housing, etc.
So - in 1990, it was obvious that reforms had to be made. In Gdańsk, the workers were incredibly hostile to any changes, and as a consequence, it was politically impossible to change anything there. They drowned in a sea of debt, and so they were taken over by the Gdynia shipyard in 1998. We can observe that the Gdańsk shipyard was never really economically viable in the free market as a result, not least because of the problematic labour relations.
What about the other two? Well, Szczecin was hailed as a perfect child of the free market. They had sensible managers, and the shipyard (in cooperation with workers) was able to get rid of the kindergartens, hospitals, etc and focus on the role of shipbuilding. It was a great success, wages were increasing quickly, they were winning orders on the free market, workers were happy with the management, so in short, great. Unfortunately, it was also all a massive fraud. It's explained nicely here - eurofound.europa.eu/publications/article/2002/bankruptcy-of-the-szczecin-shipyard - they were essentially using money lent to build ships to actually build different ships that were overbudget / late. So, Szczecin was really an illusion - it was only working in the 1990's because of such financial tricks, and it was always doomed to fail.
Gdynia was a slightly different story. They were effectively forced to take over Gdańsk shipyard and provide it with plenty of (unprofitable) work for political reasons, while the Gdynia shipyard was also given a huge amount of favourable treatment in respect to loans, orders, tax write-offs, etc. It was a terrible deal for the Polish taxpayer, as the money kept coming even though the shipyard was losing huge amounts of cash.
Why was it illegal?
It wasn't quite as simple as being illegal. EU law regarding state aid is quite complex, but the basic idea is that you can provide it as long as you make an attempt to make the business profitable. The problem with it in Gdynia was that no attempt was made - you can read the press release about it here: europa.eu/rapid/press-release_SPEECH-08-588_en.pdf - in short, the money was used for daily operations, not for restructuring the company.