The mayor of a wealthy liberal enclave next to Boston posted a rebuke to President-elect Donald J. Trump Monday, pledging his city of Somerville to be a sanctuary city regardless of pressure from the incoming administration and the possible loss of federal funds.