I will be flying to Portugal soon for studies. I received a Portuguese visa D for 120 days with 2 entries to go to Portugal. I am from an non-EU country, but residing in Switzerland currently, that permit will end by the time I fly. Could I go to France so that I could fly to Portugal from Lyon , France Airport based on this visa? Or do I strictly have to fly from Switzerland and cannot enter another Schengen country? The remarks section on my visa says "Residencia Art 61".
Your type D visa allows you to be present in the other Schengen states besides the country of issue, provided that your stay in those countries does not exceed 90 days in any 180-day period. So yes, you can travel through France to get to Portugal from Switzerland during the validity period of that visa.
This was enacted by Regulation 265/2010, which amended the Schengen convention thus:
Aliens who hold valid residence permits issued by one of the Member States may, on the basis of that permit and a valid travel document, move freely for up to three months in any six-month period within the territories of the other Member States, provided that they fulfil the entry conditions referred to in Article 5(1)(a), (c) and (e) of Regulation (EC) No 562/2006 of the European Parliament and of the Council of 15 March 2006 establishing a Community Code on the rules governing the movement of persons across borders (Schengen Borders Code) ( 20 ) and are not on the national list of alerts of the Member State concerned.
The right of free movement laid down in paragraph 1 shall also apply to aliens who hold a valid long-stay visa issued by one of the Member States as provided for in Article 18.
Be careful, however: You say that the validity of your Swiss residence permit expires before you fly. If the Swiss residence permit expires before the Portuguese D visa becomes valid, then you will be without a valid visa or residence permit. In that case, unless your nationality allows you to stay in the Schengen area without a visa, you will need to leave the Schengen area between the expiration of your Swiss permit and the "valid from" date of your Portuguese visa.