If a swimmer breaks, for instance, the 100-meter free stroke record in a medley event does that record count towards the hundred meters discipline or are those records held apart?
This is clear in the rules of swimming. For example, take the USA Swimming (official web site) rules, which follow from FINA. In section 102.24, Timing Rules one finds:
102.24 TIMING RULES
- Requirements for Official Time
A. Performance Requirements
(1) An official time can be achieved only in USA Swimming sanctioned or USA Swimming approved competition, or in an observed swim in accordance with all applicable rules. It may be achieved in:
(a) Any heat
(b) A swim-off
(c) A lead-off leg in a relay
(d) A split time recorded from the official start to the completion of an initial distance with a legal finish within a longer event, provided the swimmer completes the event or the lead-off portion of the relay in compliance with applicable rules.
(e) A time trial or a record attempt.
So, it must be a lead off-leg of the relays (such as Ryan Murphy's 100 back time at the 2016 Olympics). The freestyle portion of the medley relay is not the lead off leg, so that would not count. As a general principal, a relay start gives you about a 0.7 second advantage over a flat start (not firm science, just 40+ years of experience).
As noted in the comments, it is then also possible that the lead-off leg of an individual medley event (50 or 100 fly for the 200 or 400 IM) could also be an individual record. Similarly, although the OP specified 'medley', splits of longer races (i.e. 100 fly during a 200 fly, or 400 free during the 800 free) are also fair game for records.