How to connect an iMac 21.7 inch 2009 as a monitor to a MacBook Pro late 2013
You can't.

Only the 27" iMac's from 2009 were able to use Target Display Mode via mini DisplayPort or Thunderbolt


How do I connect my Mid-2010 iMac to my Late 2015 Macbook Pro
Use your iMac as a display with target display mode