Notice Period and Employment Terms
If your terms of employment stipulate that your notice period is 2 months or 2 months' salary in lieu of notice, then it is up to you to decide whether you should serve 2 months or get relieved immediately after paying 2 months' pay. If you choose the second option, the company cannot ask you to work for 2 months. Once you have paid 2 months' pay, you are discharged, and the company has no grounds to sue you. There are no legal complications.
Company's Perspective on Notice Period
On the other hand, imagine that the company does not want your service. The company will give you a notice that your service will end after two months. If the company wants you to be relieved immediately, it will pay you 2 months' pay and ask you not to come in from tomorrow.
In the former case, the company will utilize your labor/service for two months and, in return, pay you a salary. During this period, you can find alternative employment. In the latter case, the company will not require your service for two months but will pay you 2 months' pay and ask you to leave immediately. This 2 months' salary compensates for the loss of income until you find employment.
Employee's Options During Notice Period
Similarly, you can either inform the company that you will stay for only 2 more months, during which you will contribute your service and receive remuneration, i.e., a salary. During this period, the company can search for a replacement. Alternatively, you can state that your service will not be available from tomorrow and request two months' pay, which the company can use to provide additional remuneration to existing staff or hire a temporary employee in your place. Therefore, there is no illegality in receiving payment and being relieved without notice.