What is the relation between beamforming design and user scheduling in massive MIMO systems?
Neither 'comes first', nor are beamforming and scheduling coupled to each other in the way I think you believe they are.  

It also can depend a bit on the exact technology you have in mind.  Beamforming used in Wifi vs the beamforming used in 5G/massive MIMO, while fundamentally the same thing, are used in very different ways, and to slightly different ends.  

Let's talk about beamforming in the context of Wifi first.  

I suspect what you're imagining is that each user/client device connected to a Wifi AP would need its own beam, resulting in a problem of how to decide who gets a beam if the number of available beams exceeds the number of clients wanting to connect.  Or something loosely along those lines?  

With Wifi, there is only 1 beam per channel.  At the simplest, this means that regardless of the number of client devices, they all share the same beam, and a channel state for each device is kept and switched to every single time the Wifi AP transmits something intended to a specific client.  

Remember, with Wifi, every device within range (including those not actually connected to the Wifi network) will hear all the transmissions from the AP regardless of which device those transmissions are actually intended for.  This is why encryption is such a big deal for Wifi, because this is all that prevents anything in range from eavesdropping on everything talking with a given AP.  This also means that the AP can only transmit packets intended for 1 device at a time.  

The concept of each device maintaining a constant physical radio link is not how it really works.  There are very specifically defined times where a client device can send an RTS (request to send) packet, and it will not send any data to the AP until the AP responds with a CTS (clear to send) packet.  So no matter what, only one device at any given time is ever actually allowed to transmit data to the AP.  

As a result, the beam is simply formed however it has previously been determined to be formed for whichever client is currently being sent some packets.  It switches at a per-packet level as determined by the intended receiver of a packet.  So the beamforming is totally automatic and transparent from the point of view of network scheduling.  Network scheduling is done entirely on a need and QoS basis, while the beamforming doesn't care about that.  The beamforming is done on a 'whatever is doing the talking at this moment' basis.  One channel, one beam.  

I know your question is most definitely NOT about Wifi, but I wanted to touch on that because it provides some important context and contrast for discussing what you were actually asking about, which is beamforming in the context of massive MIMO (in other words, 5G).

Before anything else, I do want to mention that the definition of massive-MIMO is that there are many more antennas than there are terminals.  In other words, by definition, the situation which I think you may be imagining, where there are insufficient beamforming resources available for the number of connected devices (terminals) cannot happen.  Even if many terminals are directly adjacent to each other, for there to even be multiple beams, that also means each one is a different channel (frequency at a given instant).  So different beams, to be different beams in the first place, must not interfere with each other, so having every single one of, say, 100 beams pointed at the same spot is fine, because presumably you have a 100 different channels as well.  A base station/cell will handle up to the maximum designed terminal count and no more at the same time.  So the number of connected devices will never exceed the beamforming capacity.  User scheduling in this case would be very analogous to what I described with Wifi earlier, only instead of a single device, it is a set of many devices simultaneously, but otherwise it is the same situation.  If you pretend a wifi connected device represents 100 users, and there are 1000 phones in a given cell, this can be imagined like a Wifi AP with 10 devices.  Each device has stored parameters on how to form the beam, and the beam is switched to said forming parameters depending on which device is currently taking up network time.  

It is no different with massive-MIMO.  Just was with Wifi, where there is only 1 beam per channel, but also only ever one device utilizing a given channel at a given time, the beamforming capacity is never exceeded by the terminal count.  Instead of 1 beam and 1 terminal however, it is many many beams and many many terminals, but each terminal has channel state information stored and updated periodically, so no matter what the actual subset of terminal devices currently being communicated with, the beams are formed to match those devices. 

So again, just like with Wifi, beamforming and network scheduling do not influence one another, but rather beamforming is done transparently and depends only on the specific terminals the scheduler is currently communicating with.  

Bonus answer to this question that you didn't ask: How does the beamforming used in massive-MIMO differ from more familiar line-of-sight beamforming applications?

What a great question!  Earlier, when I said massive-MIMO's beamforming was fundamentally the same as any other beamforming, I meant that it is the same in the most theoretical, mathematical sense.  It is transmitting a signal using multiple antennas but out of phase in just the right way to enhance transmission.  The similarities end there, however. 

It is important to understand that the idea of gain lobes and steering lobes (the most familiar form of beamforming, with lobe being synonymous with 'beam') is something that makes sense when you primarily have line-of-sight transmission, or at least, minimal reflections from the environment.  

This is about as far from the typical cell phone signal propagation and environment as you can get.  Any signal will reflect all over the place, and propagate along multiple simultaneous paths, resulting in a single signal interfering with itself (to the detriment OR benefit of reception/SNR) because each path is also going to be slightly out of phase with the other copies propagating.  Indeed, except for the limited case of being outside with direct line-of-sight to a cell base station, nearly all cell phone transmissions are going to be very indirect with multiple reflections of propagation, as well as multiple paths with different sequences of reflections in between the base station and the handset.  

Hopefully it is becoming clear that the concept of a beam or a lobe is no longer really applicable to this situation.  And this is what ultimately makes beamforming in massive-MIMO so different.  There is no beam and you are not forming it.  Rather, you are using a (frankly, incredible) amount of processing power to determine a matrix of signal transfer functions for a given terminal, and optimize the transmission from multiple antennas phase (along with the usual MIMO goodness which encodes redundancy and extra data by leveraging the expected multipath propagation) in ways that defy any good mental imagery.  You are transmitting from multiple antennas and their phases are whatever they need to be that yields the best SNR based on the unique signal propagation paths, reflections, all of it, that occur between the base station and that specific terminal.  These might be different depending on very subtle changes in the environment, like a fridge door being open or not, or really anything that might reflect the signal and is, at that moment, reflecting part of the signal being received by the terminal.  Like I said, it is fundamentally the same as beamforming, while being as totally different from anything one might ever think to call 'beamforming' as one can get.  Signal or transmission forming might be more appropriate.  But at the core, it is just playing with the phases of some antennas, and that is beamforming.  In that way, and only that way.  

One final difference is to what ends this 'beamforming' is done.  In the more familiar example, it is obviously merely intended to enhance the signal strength/SNR of a channel.  

However, in massive MIMO, while this is certainly part of the reason, the arguably primary goal of this non-classical beamforming is increasing channel capacity. 4G is already operating at the maximum theoretical limits for channel capacity, so 5G's massive MIMO increases beyond this by, well, cheating.  The beamforming can also leverage multipath propagation to cause a signal to largely cancel out for one terminal, while being received loud and clear for another (albeit, spatially separated) terminal.  This aspect can perhaps be imagined, at least in abstraction, as more like classical beamforming.  If you have beams that only reach a small area close to the intended terminal, then you can reuse the same spectrum for another beam to a sufficiently spatially separated terminal. This is formally called Space-division multiple access. 

This extra capacity does, of course, depend on terminal locations.  Since the same channel is being reused for multiple beams, then those beams would need to be used to talk to two terminals with sufficient spatial separation.  So it is to be expected that the actual capacity of a given cell will have some variability, but this is not really an issue - the terminals are already being multiplexed in the time domain (CDMA is a form of this, for example), so much like a multiuser operating system, each terminal gets a certain slice of the time division pie, and device count and total demand will impact the performance of everything in a given cell.  But network scheduling would only see this as a variable number of channels, and ultimately, it is simply a resource allocation problem.  It neither knows nor cares about anything going on with beamforming specifically.  If a ton of terminals are in one spot, then worse comes to worse, they just have to wait their turn.  

This lets you potentially increase the effective channel capacity of a given area by many times, and it scales extremely well.  The only downside is it requires an immense amount of computation/processing to be done by the base station, but today's integrated circuits/processors/DSPs are finally up to the challenge.   

Just keep in mind that the above description is using 'beam' in a very abstract way, as again, there is nothing anyone would call a beam, but rather some long propagation of multiple transmissions reflecting multiple times and propagating along multiple paths to eventually be received by a terminal somewhere.  There is going to be some directionality there obviously, but the spatial separation might be far closer than with traditional beamforming thanks to leveraging multipath propagation and how it can vary quite a bit in many environments over relatively short distances.