It can do a variety of things to achieve this.
You can either interface the official server using a custom-made wrapper, that dumbs it down to a world generator, throwing any physics and game updates out of the window, then send the data to the client running on the website using websockets or AJAX. This is legal, as far as I'm aware, as the server is treated like a black box. The original Bukkit server did this and just stepped in at points to do any plugin-related modifications.
Or you can implement everything in JavaScript, including the random generator Java uses, the exact noise algorithm the game relies on and the details of the world generator. This however is not only slow, but error prone, as any small detail can majorly change the outcome of the generator. It also requires either heavy reverse-engineering or disassembling the game, which isn't as clear on the legality site based on the EULA:
Although we license you permission to install on your device and play our Game, we are still the owners of it. We are also the owners of our brands and any content contained in the Game. Therefore, when you pay for our Game, you are buying a license to play / use our Game in accordance with this EULA - you are not buying the Game itself. The only permissions you have in connection with the Game and your installation of it are the permissions set out in this EULA.
Any Mods you create for the Game from scratch belong to you (including pre-run Mods and in-memory Mods) and you can do whatever you want with them, as long as you don't sell them for money / try to make money from them and so long as you don't distribute Modded Versions of the Game. Remember that a Mod means something that is your original work and that does not contain a substantial part of our code or content. You only own what you created; you do not own our code or content.