In order to get the GstCaps you need to get the GstSample and the GstAppsink first. Based on the code you showed, you could do something like this:
auto appsink = GST_APP_SINK(sink);
auto sample = gst_app_sink_pull_sample(appsink)
auto caps = gst_sample_get_caps(sink);