My understanding is that it is legal since it is just engineered to be (somewhat) compatible with ATmega328p but their difference are substantial if you deep dive.
It has a RISC core and its core instructions are quite different from ATmega328p. Most multi-cycle instructions are replaced by single-cycle instructions or less cycle instructions. And the core runs at 32Mhz from 1.8V-5.5V.
The peripheral registers are largely (backward) compatible with ATmega328. However, LGT has more or advanced peripherals.
- 2 16-bit timers, with capture and compare output
- ADC has 12 bits instead of 10.
- DAC, so you don't need PWM to emulate DAC.
- 9 high current PWM. 3 complementary PWM with dead band control.
- PGA 1x-32x differential amp. Which saved me 1 op-amp.
- 16 bit computing accelerator/Co-processor.
- High and adjustable current GPIO (so you can light up LEDs without current limiting resistors).
These peripherals provide lots of additional registers for control and status reporting that don't exist on ATmega.
Development environment is also different. The best way for hobbyists to develop on this chip is either using LGT Arduino Core but not ATmega328 Arduino Core:
https://github.com/dbuezas/lgt8fx (Arduino IDE)
or
https://community.platformio.org/t/how-to-add-lgt8fx-board/13294 (PlatformIO) Or you can use their official SDK for development which is very different from AVR's environment.
LGT8F328p also has SSOP20 and LFP48 package offering smaller or larger number of GPIOs, which are not so well known by DIY community since they are not similar to ATmega328p.
So in general LGT is a different, forward engineered chip and highly unlikely a direct silicon clone copied by reverse engineering.
In general having peripheral registers and pin compatibility are not illegal, unless the IP core of the peripherals are stolen from ATmega328p. And since CPU instructions (and clock trees) are quite different, if assembly language is used for development, developer would likely feel they are two distinct MCUs. It is just that a C compiler and Arduino framework can hide those details and make them similar.
However, the laws and regulations differ across countries and states so I am not sure if that applied to all markets. And there is natural murkiness in what is an IP and what is not. In software, API similarity could result in infringement but in the world of MCU pin compatibility would not, despite they are both "interface similarity" issues.