Yes, in this situation you'll need to file tax returns for both New York and Maryland.
This is a common situation for military reservists and anyone that lives in one state and works in another.
You'll need to file a New York Nonresident Return since you earned income in New York but didn't live there. You're taxes by New York only on the income earned from your reserve duty in New York. The New York taxes that were withheld from your paycheck will be reported on this return.
Then, you'll need to file a Maryland Resident Return and report the same income since you lived there, even if you didn't earn any income in Maryland. The state of Maryland taxes its residents on income received from anywhere. Maryland will give you a credit for the taxes that you paid to New York to avoid double taxation. This credit only applies to the income that's taxed in both states, and may or may not completely eliminate your Maryland tax.