You have strings of 13 cells all joined in parallel, so they all hold each other at the same voltage. There's 13 strings of 13 cells in series. Each string has a connection from the positive and negative to the BMS. As the positive of one string is joined to the negative of the next, they share a common wire. That means you need 14 connections to the BMS.
There's 13 chanels on the BMS. Each channel monitors the voltage of one string. If any string goes above 4.25v, the BMS shuts off the negative charging connection. If any string goes below 3.0v, it shuts off the discharge negative.
When you charge the battery, all strings rise in voltage. When any string goes over about 4.15v a transister opens a route to ground through a bleed resistor, so the charge trickles out until it goes down to 4.15v. The charger can fill up faster than the charge can trickle out. It will continue until any cell reaches 4.25v, then shuts off. After that, all cells above 4.15v drain down to 4.15v to balance them.
Its a bit like a row of buckets with a small hole drilled in them all at the same level 2 inches from the top. You can fill them up to the top with a hose, but they always end up with exactly the same level - 2 inches from the top - as long as you fill them past the hole.
Finally, there's normally a shunt on the output negative. The BMS monitors the voltage drop across that, which is proportional to current. When the current goes above the maximum value, the BMS shuts off the output negative.
Some sophisticated ones have temperature detection and manual shut-off (switch).