I don't think anything was ever mentioned about Data's rank just prior to being posted to the Enterprise. It's possible he was promoted to Lt. Cmdr when he was assigned to the D...
Backed up by the costuming mistake in the past scenes of All Good Things
, where he is still a Lieutenant. (ie. Picard forgot to promote him this time).