Generally speaking, it's not forbidden to visit other countries (and certainly not to transit through another Schengen country before going to Portugal) but it's best to stick to the itinerary you submitted when applying for the visa. If you do not, you might be questioned about it and should have a good reason to have a Portuguese visa.
Staying a couple of days somewhere else at some stage during your stay or reusing the visa later for another purpose later should be no problem but entering Portugal on the 10th day of your first trip to Europe or worse never going there at all would raise red flags as it would suggest that Portugal never was your real destination. See also Can I use my Schengen visa for a completely different purpose and entry point? and related questions for more details.