Does MA require permit to replace old K&T and if no how do I know if work is done to code?
For all of the questions you asked: Consult your town's building department (or equivalent if it goes by a different name where you are from).

They should be able to pull the permit history for your home if requested and tell you what type of electrical work requires a permit.

If you find the that work was done without a permit:

If you are solely concerned about safety and do not want to have to worry about an inspector forcing you to tear open your walls if previous work was unpermitted, you can always pay an independent inspector to come look things over as well. Many people have this type of inspection done prior to purchase of the home and these inspections should be able to tell you if the visible elements (e.g. wires at device boxes, electrical panel) look to be done to code which can serve as an indicator of the quality of the work hidden behind the walls. However, "after the work is completed" inspections on electrical can still miss a lot of potential safety hazards even when the visible elements look okay (e.g. splices done directly in the wall -- I personally discovered some of these on my home after having an independent inspection prior to purchase).

A city inspector may require the walls to be ripped open to inspect the previous work because of the limitations of an "after the work is completed" inspection. Some city inspectors may not require this if the visible electrical work appears to be up to code. However, the city inspector can potentially require you to rip open the walls regardless if the work was done without a permit.